Android 应用退到后台,再次进入应用重启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;
            }
        }

 

你可能感兴趣的:(Android,零碎知识点记录)