我的活动A与android:launchMode="singleTop"在清单.
如果我去的活动B,C和D在那里我有菜单快捷方式回到我的应用程序根系活力(A).
代码如下所示:
Intent myIntent = new Intent(getBaseContext(), MainActivity.class);
startActivity(myIntent);
Run Code Online (Sandbox Code Playgroud)
但是,不是返回到A我已经存在的实例,MainActivity.class而是创建一个新实例 - >它onCreate()转而不是onNewIntent().
这不是预期的行为,对吗?
我的目标是,如果用户点击通知,则返回上一个活动.我以这种方式在服务onCreate()中创建通知:
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Run Code Online (Sandbox Code Playgroud)
但是当我点击通知时,这将转到MainActivity而不是之前打开的最后一个单击主页按钮.
在清单中,我尝试使用launchMode ="singleTop","standard"和"singletask"来使用MainActivity,但没有成功.
谢谢.