Android 首次安装,通过系统安装页面“打开”按钮,按 home 键返回桌面,通过桌面图标打开 App,导致 App 重新启动。

Android 首次安装,通过系统安装页面“打开”按钮,按 home 键返回桌面,通过桌面图标打开 App,导致 App 重新启动。这个是 Android OS 本身的 bug。

解决方案:在App的启动页面加入如下代码

        /*防止首次安装点击home键重新实例化*/
        if (!this.isTaskRoot()) {
            Intent intent = getIntent();
            if (intent != null) {
                String action = intent.getAction();
                if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
                    finish();
                    return;
                }
            }
        }

你可能感兴趣的:(Android 首次安装,通过系统安装页面“打开”按钮,按 home 键返回桌面,通过桌面图标打开 App,导致 App 重新启动。)