首页 > 解决方案 > 从通知中的待处理意图启动启动器活动

问题描述

如果我的启动器活动 A 现在正在运行。

一些活动在活动 A 之上。

例如,这是我的 backstack ABC

我需要按下通知启动A,清除ABC然后打开A,或关闭B和C并通过onNewIntent恢复A

我尝试添加一些标志,但没有任何帮助!

 private void push(NotificationModel model, Intent intent) {

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    //here I'm trying to add flags to my intent
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

标签: androidandroid-intentandroid-activityandroid-pendingintentflags

解决方案


android:launchMode="singleTop"在您的清单文件中使用。

它能做什么:

在这种启动模式下,如果当前任务的顶部已经存在一个 Activity 的实例,则不会创建新的实例,Android 系统将通过onNewIntent().

如果任务顶部不存在实例,则将创建一个新实例。


推荐阅读