前言
1、這個問題困擾我n久n久
2、網上出現很多解決方案,大多是設置lanchModel 雖然這樣能解決1些問題,但是不能完全解決,且與我的情況也不符合
解決方案:
方案1:
1、如果你的程序有管理activity的棧,可以在啟動LogoActivity的onCreate中判斷這個棧是存在其他的activity 如果有 本身直接 finish + return 。這樣是ok,但是總感覺有種不靠譜的感覺。
方案2:
2、 無意中發(fā)現原來是創(chuàng)建的快捷方式的問題,快捷方式的flag或intent的創(chuàng)建方式致使重啟。
關于如何創(chuàng)建快捷方式 這里省略
看代碼
public void addShortCut(){
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 設置屬性
...
...
...
//點擊快捷方式的操作
這里的intent 必須要新創(chuàng)建的,不能使用 getintent 或getPackmager.getLaunchIntentFor...等方式創(chuàng)建,如果這樣創(chuàng)建致使 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);
//廣播通知桌面去創(chuàng)建
this.sendBroadcast(shortcut);
}