如何跟踪活动以便稍后重新启动
我有一个活动需要执行许多操作才能执行其任务。在该活动的 onResume() 方法中,将进行检查以确定是否满足要求,如果不满足,将激活一系列活动来完成要求。记录原始活动以便在收集需求后返回原始活动的最佳方法是什么?
我的解决方案是通过活动调用链传递原始活动的意图内容,以便在收集所有需求后能够再次重新启动原始活动,但我觉得这不是最佳解决方案。
谢谢
I have an activity that requires a number of actions to be done before it can perform its task. in the onResume() method of that activity a check is done to determine if the requirements are met, if not a chain of activities will be activated to complete the requirements. what would be the best approach to keep record of the original activity in order to get back to it after the requirements have been gathered.
My solution was to pass the original activity's intent contents through the activities call chain in order to be able to restart the original activity again once all the requirements are gathered but i feel that this is not the optimal solution.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望这是有道理的,我正在尽力理解您的要求,因为您实际上并没有说出应用程序的作用。
我会让基本活动检查先决条件,然后使用
startActivityForResult
启动第一个相关的辅助活动。我会让辅助活动使用setResult(RESULT_OK)
/finish()
这会将控制权带回基本活动。我会让基本活动每次都重新检查先决条件,而不是试图记住应该完成的内容。如有必要,共享首选项可用于存储辅助任务何时完成先决条件。Hope this makes sense, I'm trying to understand your requirements as best I can since you don't actually say what the application does.
I'd have the base activity check the prerequisites, then fire off the first relevant secondary activity with
startActivityForResult
. I'd have the secondary activity usesetResult(RESULT_OK)
/finish()
which would bring control back to the base activity. I'd have the base activity check the prerequisites anew each time rather than trying to remember what had supposedly been completed. The shared preferences could be used to store when prerequisites were completed by the secondary tasks if necessary.