android 后台进程满了 app每次进入页面 重启

多见于华为手机
比如 华为P30

1.在基类BaseActivity添加如下的方法:
 

@Override
    public boolean moveTaskToBack(boolean nonRoot) {
        return super.moveTaskToBack(true);
    }

2.在App的启动页 oncreate 里加入代码 判断:
 

if (!this.isTaskRoot()) {
            Intent mainIntent = getIntent();
            String action = mainIntent.getAction();
            if (mainIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
                finish();
                return;
            }
        }

一般能解决掉 90%以上的 app进程占用较大时 ,app每次进入 重新加载问题。
场景:用户通过通知栏 或Home 键 跳出  (查看短信等) 再次进入 出现重新加载App问题.

猜你喜欢

转载自blog.csdn.net/weixin_40611659/article/details/105815126
今日推荐