Android Home鍵 點捷徑功能表應用重啟問題【完美解決】,androidhome
前言
1、這個問題困擾我n久n久
2、網上出現很多解決方案,大多是設定lanchModel 雖然這樣能解決一些問題,但是不能完全解決,且與我的情況也不相符
解決方案:
方案一:
1、如果你的程式有管理activity的棧,可以在啟動LogoActivity的onCreate中判斷這個棧是存在其他的activity 如果有 本身直接 finish + return 。這樣是ok,但是總感覺有種不靠譜的感覺。
方案二:
2、 無意中發現原來是建立的捷徑的問題,捷徑的flag或者intent的建立方式導致重啟。
關於如何建立捷徑 這裡省略
看代碼
public void addShortCut(){
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 設定屬性
...
...
...
//點擊捷徑的操作
這裡的intent 必須要新建立的,不能使用 getintent 或者getPackmager.getLaunchIntentFor...等方式建立,如果這樣建立導致 setflag無效
Intent intent = new Intent();
intent.setComponent(getComponentName());
intent.setAction(intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
//要添加這句話
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED| Intent.FLAG_ACTIVITY_NEW_TASK);
// 設定啟動程式
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
//廣播通知案頭去建立
this.sendBroadcast(shortcut);
}