基于额外内容的 REORDER_TO_FRONT
在一个应用程序中,我非常重用“活动”,它显示了特定日期发生的事情的列表。该日期是使用 Intent Extras 指定的。
我的问题是,如果用户从 day=1
开始,然后从菜单中选择 day=2
,然后选择 day=1
,然后我希望后退按钮转到day=2
,然后返回主页。也就是说,我想要执行REORDER_TO_FRONT
,但不仅基于活动的名称,还基于其附加内容。
似乎没有任何适合此目的的意图标志。我考虑过使用 onNewIntent 实现我自己的“子活动堆栈”,但它可能不会很好地工作。
您在应用程序中解决过类似问题吗?是否有一种方法可以以编程方式访问活动堆栈,并选择适合返回的活动堆栈?
In an app I have very reused Activity, that shows a list of stuff happening on a specific day. The day is specified using Intent Extras.
My problem is, that if the user starts at day=1
, then chooses day=2
and then day=1
, from the menu, then I would like the back button to go to day=2
and then home. That is, I want to do REORDER_TO_FRONT
, but not just based on the name of the activity, but also its extras.
There doesn't seam to be any intent flags suitable for this purpose. I've considered implementing my own 'sub activity stack' using onNewIntent
, but it probably wouldn't work very well.
Have you tackled similar problems in your apps? Is there perhaps a way to programmatically access the activity stack, and choose which one is suitable to return to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
管理您自己的活动堆栈!如果我没记错的话,您每天都会使用相同的 Activity 来显示。使其成为单顶(FLAG_ACTIVITY_SINGLE_TOP)。在启动意图中,传递当前堆栈,在示例中为“121”。
通过使用较小的堆栈启动 Activity 来响应后退按钮事件:“12” - 或者如果堆栈已经是“”,则让 Activity 处理后退事件。然后,正如您提到的,使用 onNewIntent 函数来更新您的 Activity。
Manage your own Activity stack! If I'm not mistaken, you use the same Activity to display each day. Make it single top (FLAG_ACTIVITY_SINGLE_TOP). In the launching intent, pass on the current stack, in your example "121".
Respond to the back button event by launching your Activity with a smaller stack: "12" - or if stack is already "", then just let the Activity handle Back event. Then as you mentioned, use the onNewIntent function to update your Activity.