应用退到后台,再次进入应用重启App问题,特别是华为

问题描述:

App第一次安装后打开,退到后台再次进入应用时候,之前的页面不保留,App重新启动。问题主要出现在华为手机上。

解决方法:

1、在App的基类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;
            }
        }

猜你喜欢

转载自blog.csdn.net/nsacer/article/details/80346843