Android 在安裝完成界面直接打開應用,按HOME回到桌面,再次點擊應用圖標,會重新走 android.intent.category.LAUNCHER Activity

Android 在安裝完成界面直接打開應用,按HOME回到桌面,再次點擊應用圖標,會重新走 android.intent.category.LAUNCHER Activity,解決方案如下:

在該Activity的onCreate加入如下代碼,

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        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;
                    }
                }
        }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章