标记为“答案”的解决方案有效,但有一个对我来说至关重要的缺点。
With FLAG_ACTIVITY_CLEAR_TOP your target activity will get onCreate called before your old activity stack receives onDestroy. While I have been clearing some necessary stuff in onDestroy I had to workaroud.
Intent intentHome = appContext.getPackageManager()
.getLaunchIntentForPackage( appContext.getPackageName());
intentHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// need to match launcher intent exactly to avoid duplicate activities in stack
if (mIsLaunchIntentPackageNull) {
intentHome.setPackage(null);
}
appContext.startActivity(intentHome);
然后在清单中定义的主要活动中,我添加了这一行:
public void onCreate(Bundle savedInstanceState) {
[class from above].handleLaunchIntent(getIntent());