Android后退按钮新意图或finish()
我有一个问题。我有一个列表视图 (A) 和一个详细信息视图 (B)。
在 B 上,我有一个“查看列表”按钮,始终将用户带到列表。问题是,我可以通过通知到达 B,而不必从 A 到达。
因此,当单击 B 时,我不能只使用 finish(),因为我可能是从通知进入的,所以我可能需要开始一个新的某些情况下的活动。
我如何可靠地判断我是来自 A 还是来自通知,以便我可以采取正确的操作。
除此之外,这是我应该担心的事情吗?或者每次都开始一个活动就可以了。在我在A->之间跳跃的情况下B-> A-> B-> A-> B 一遍又一遍...从来没有调用过 finish()...这会减慢速度吗?
谢谢,
杰拉德。
I have a question. I have a list view (A) and a details view (B).
On B, I have a "view list" button that will always take the user to the list. The thing is, I can get to B via a notification and not necessarily from A.
So when clicking B, I can't just use finish() because I could have come in from a notification, so I may need to start a new activity in some cases.
How do I reliably tell if I came in from A or from a notification so that I can take the right action.
Added to that, is this something I should be worrying about? Or is it ok just to start an activity every time. In the case where I bouncing between A -> B -> A -> B -> A -> B over and over... never once calling finish()... will that slow things down?
Thanks,
Gerard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您以意图启动 Activity B 时,添加一个 extra,然后检查 Activity B 中 extra 的状态。这是一个使用字符串的示例,尽管您可以使用其他变量类型(如布尔值或 int):
然后在 Activity B 中您可以获得额外变量:
When you start Activity B with an intent add an extra and then check the state of extra in activity B. Here is an example using strings although you could use other variable types like a boolean or an int:
Then in Activity B you can get the extra variable with:
当你从 A -> 进入时,你可以添加一个意图额外标志。 B,说一个布尔标志。
在活动 B 上,如果它不携带额外的意图,您可以将标志默认为 false。
You can add an intent extra flag when you go from A -> B, say a boolean flag.
On Activity B, you can default the flag to false if it doesn't carry the intent extra.