如何跟踪活动以便稍后重新启动

发布于 2024-11-01 09:19:39 字数 197 浏览 2 评论 0原文

我有一个活动需要执行许多操作才能执行其任务。在该活动的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆沫 2024-11-08 09:19:39

希望这是有道理的,我正在尽力理解您的要求,因为您实际上并没有说出应用程序的作用。

我会让基本活动检查先决条件,然后使用 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 use setResult(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文