在android中终止向导的最佳方法

发布于 2024-09-25 21:37:22 字数 454 浏览 9 评论 0原文

我在android中有一个预订向导,当我说向导时,我的意思是我有多个活动(意思是屏幕),这些活动从一个活动传递到另一个活动,直到预订完成。在每一步中,我的信息可能无效,因此我必须回溯 2-3 个活动并重新开始,我回溯的所有活动都应该被销毁,他们可能需要使他们填充的单例数据容器无效他们的数据。 我想到了两种方法来做到这一点:

  1. 使用 startActivityForResult() 启动与向导相关的所有活动,以便在活动完成时收到通知以及错误代码(完成正常或发生错误)并采取行动相应地(例如:如果中间一个活动失败,它将返回失败,前一个活动也将返回失败,直到我到达向导的第一个活动,在该活动中我要么用对话框声明错误,要么显示“谢谢”屏幕。)
  2. 我可以发送对具有某些参数的意图的反应,这样我就有一个“关闭和干净”的意图消息来关闭之前的活动等...

哪种方法更好,还有其他有趣\有效的方法来做到这一点?

I have a reservation wizard in android, when i say wizard i mean i have multiple activities (meaning screens) that are passed from one to another until booking is complete. in each step of the way my info may be invalid and so ill have to back track 2-3 activities and start all over, all the activities i back tracked should be destroyed, they may need to invalidate a singleton data container that they filled with their data.
I thought of 2 ways to do this:

  1. start all activities related to the wizard with startActivityForResult() so i get notification when an activity is finished and with which error code (finished OK or error occurred) and act accordingly (for instance: if in the middle an activity fails it will return failed and the previous one will return failed as well until i get to the wizard's first activity where i either declare the error with a dialog or show the 'thank you' screen.)
  2. I can send an react on intents with certain parameters so i have a 'close and clean' intent message that close down the previous activity etc...

which way is better, any other interesting\efficient way to do this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

来世叙缘 2024-10-02 21:37:22

我得到了一个提示,让我朝不同的方向思考:

  1. 使用不可见的活动,或者使用本地服务,这是“大脑”,知道在每一步要采取什么行动。要删除完整的不需要的活动堆栈,我应该在接下来要使用的最底部的活动上使用 FLAG_ACTIVITY_CLEAR_TOP 。
  2. 另一种选择是包含所有
    我想玩的活动
    他们在栈里面的位置
    一个 ActivityGroup 对象,它保留
    所有活动都处于活动状态(如选项卡中)
    并在堆栈上,但你可以控制
    显示哪一个以及哪一个是
    不是。活动组将包含
    状态机逻辑有关
    哪个 Activity 不应该
    显示并且应该是
    处置。

I Got a hint that got me thinking in a different direction:

  1. use an invisible Activity, or alternatively , a local service,that is the 'brains' that known on each turn of the way what action is to be taken. to remove a complete stack of unneeded activities i should use the FLAG_ACTIVITY_CLEAR_TOP on the bottom most activity i want to use next.
  2. Another options is to enclose all
    the activities i want to play with
    their pposition on the stack inside
    an ActivityGroup Object which keeps
    all activities alive (like in Tab)
    and on the stack, but you control
    which one is displayed and which is
    not. the activity group will contain
    the state machine logic regarding
    which Actvity should not be
    displayed and which should be
    disposed.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文