Android:控制点击通知时显示哪个活动
在 Android 应用程序中,我有两个活动;让我们称它们为 A 和 B。A 是主要 Activity,它包含一个调用 startActivity() 的按钮来显示 B。简而言之:
A -> B
A 有一个每分钟滴答的线程。在此勾选上,状态栏中会更新通知
这就是我所追求的:
1)当用户在 A 和 B 都不可见时单击通知时,显示 A 2)当用户在 A 可见时单击通知时,不会发生任何事情 3) 当用户在 B 可见时单击通知时,不会发生任何事情(或者,如果更容易的话,弹出 B 以显示 A)
1) 和 2) 很容易完成。 3)会启动新版本的A并将其添加到队列中:
A -> B-> A,这不是我想要的。用户必须按回键三下才能转到主屏幕
有没有办法确保单击通知将显示堆栈 A -> ?单独B还是单独A?
In an Android app, I have two activities; lets call them A and B. A is the main activity, and it contains a button that calls startActivity() to display B. In short:
A -> B
A has a thread that ticks every minute. On this tick, a notification is updated in the status bar
This is what I am after:
1) When the user clicks the notification when neither A nor B is visible, show A
2) When the user clicks the notification when A is visible, nothing should happen
3) When the user clicks the notification when B is visible, nothing should happen (or, if it is easier, pop B to show A)
1) and 2) are easy to accomplish. 3) will start a new version of A and add it to the queue:
A -> B -> A, which is not what I intended. The user has to press back three times to go to the home screen
Is there a way to ensure that clicking the notification will either show the stack A -> B or A alone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将活动 A 的标志设置为 singleTask,并将新的
startActivity()
意图捕获到活动 A 的onNewIntent(Intent i)
(您应该覆盖它)。希望这有帮助!You should set the flag of activity A to singleTask and catch the new
startActivity()
intent to theonNewIntent(Intent i)
of activity A (which you should override). Hope this helps!在
startActivity()
方法中设置FLAG_ACTIVITY_CLEAR_TOP
标志。之后,如果您想重新创建活动 A,请设置 FLAG_ACTIVITY_SINGLE_TOP 标志。
或者,如果您想重用活动 A,请设置
FLAG_ACTIVITY_SINGLE_TOP
标志。Set
FLAG_ACTIVITY_CLEAR_TOP
flag instartActivity()
method.After that, if you want to recreate activity A, set
FLAG_ACTIVITY_SINGLE_TOP
flag.Or if you want to reuse activity A, set
FLAG_ACTIVITY_SINGLE_TOP
flag.