在活动之间保留片段状态 [英] Retain Fragment state between Activities

查看:27
本文介绍了在活动之间保留片段状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在活动之间保留一个Fragment?

Its possible to retain a Fragment between Activities?

假设我有 Activity A,其中 Fragment F_Left 位于左侧,而 Fragment F_Right 位于右侧.如果我想启动一个新的 Activity 并保留 Fragment F_Left...我该怎么做?

Lets say I have Activity A with Fragment F_Left placed at the left and Fragment F_Right placed at the right. If I want to launch a new Activity and keep Fragment F_Left... how can I do it?

我可以在活动之间保持 Fragment F_Left 状态吗?

Can I retain Fragment F_Left state between activities?

请注意,我想启动一个新活动,因为 Fragment F_Left 是我的应用程序菜单,而 Fragment F_Right 完全改变了用户操作的上下文...和我的应用程序有很多操作,所以每个操作都有一个活动是有意义的.

Note that I want to launch a new Activity because Fragment F_Left is my app menu and Fragment F_Right changes completely the context of the user operations... and my app have many of operations, so it makes sense to have an Activity per operation.

我知道可以将 Fragment 保留在 Activity 中,但是由于 Fragment 生命周期与容器 Activity 密切相关 我不知道这是否可以在活动之间保持 Fragment 状态.

I know its possible to retain Fragment within an Activity, but as Fragment life cycle is closely tied to the container Activity I don't know if this is possible keep Fragment state between Activities.

推荐答案

如果我想启动一个新的 Activity 并保留 Fragment F_Left...我该怎么做?

If I want to launch a new Activity and keep Fragment F_Left... how can I do it?

不要启动新活动.

我可以在活动之间保留 Fragment F_Left 状态吗?

Can I retain Fragment F_Left state between activities?

不是自动的.它不是同一个片段.您将在活动之间传递数据以供片段使用,这与完全没有任何片段的情况没有什么不同.

Not automatically. It is not the same fragment. You would pass data between the activities for use by the fragment no differently than you would without any fragments at all.

这篇关于在活动之间保留片段状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆