android - 从通知中的待处理意图启动启动器活动
问题描述
如果我的启动器活动 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);
解决方案
android:launchMode="singleTop"
在您的清单文件中使用。
在这种启动模式下,如果当前任务的顶部已经存在一个 Activity 的实例,则不会创建新的实例,Android 系统将通过onNewIntent()
.
如果任务顶部不存在实例,则将创建一个新实例。
推荐阅读
- node.js - Nodejs WebSocket 响应被加密或不可读(连接到交换套接字)
- php - 无法通过 ajax 将字母传递给 php,但数字可以
- typescript - VS Code 在调试时使用我的 gatsby-node.ts 的内联源映射需要什么?
- java - 我如何创建一个允许输入通用密码但在 3 个三分之后程序必须关闭的登录屏幕(Java)
- python - Python- Selenium/BeautifulSoup PDF & Table scraper
- java - 如何在java中生成随机字体?
- ios - 具有本地设备服务器的 iOS 数据包隧道提供程序
- c# - xamarin 表单 - 使用 '(ProductModel)picker.BindingContext;' 造成额外不必要的回帖
- python - 我正在尝试使用 tkinter 将字典附加到 JSON 文件
- javascript - js 正则表达式 - ^ 是否具有特殊含义“在组的开头”()?