相关疑难解决方法(0)

New Intent()用Android启动新实例:launchMode ="singleTop"

我的活动Aandroid:launchMode="singleTop"在清单.

如果我去的活动B,CD在那里我有菜单快捷方式回到我的应用程序根系活力(A).

代码如下所示:

Intent myIntent = new Intent(getBaseContext(), MainActivity.class);
startActivity(myIntent);
Run Code Online (Sandbox Code Playgroud)

但是,不是返回到A我已经存在的实例,MainActivity.class而是创建一个新实例 - >它onCreate()转而不是onNewIntent().

这不是预期的行为,对吗?

android android-intent android-activity

57
推荐指数
4
解决办法
12万
查看次数

Android:从通知中恢复上次活动

我的目标是,如果用户点击通知,则返回上一个活动.我以这种方式在服务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,但没有成功.

谢谢.

android

4
推荐指数
2
解决办法
4777
查看次数

标签 统计

android ×2

android-activity ×1

android-intent ×1