1. 程式人生 > >Android APK安裝後點擊[開啟]與[完成]的區別

Android APK安裝後點擊[開啟]與[完成]的區別

1、點選[開啟]-->安裝apk後直接點選[開啟]啟動app,按home鍵後再次點選app icon啟動應用時會出現每次都從MAIN Activity重新啟動,而不是進入原來介面的問題(某些機型、系統存在此問題);

2、點選[完成]-->點選完成後,從桌面點選app icon啟動應用則不會出現[1]中的問題;

3、下面介紹一種解決方案:

在LauncherActivity OnCreate()中新增以下程式碼:

    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super
.onCreate(savedInstanceState); if (!isTaskRoot()) { /* If this is not the root activity */ Intent intent = getIntent(); String action = intent.getAction(); if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) { finish(); return
; } } }