问题描述
我想设计一个类似Facebook,Twitter或Instagram的基于提要的应用程序.在主屏幕中,我有一个FeedActivity,其中包含一个ViewPager,用于容纳3-4个片段(表示为标签)
I would like to design a feed-based app with similar design like Facebook, Twitter or Instagram. In the main screen, I have a FeedActivity which holds a ViewPager for holding 3-4 fragments (represented as tabs)
FeedActivity
++ ListOfItemsFragment (there is a ListView holding posts)
++ OtherFragment
++ SomeOtherFragment
当用户触摸帖子(在ListOfItemsFragment中列出)时,我想打开另一个活动(或ViewPager中的另一个片段).如果我打开此新活动(PostDetailActivity),并且当我返回FeedActivity时,由于再次创建了FeedActivity,所有数据都将丢失在ListOfItemsFragment中.
I would like to open another activity (or maybe another fragment in ViewPager) when a user touches a post (listed in ListOfItemsFragment). If I open this new activity (PostDetailActivity) and when I return to the FeedActivity, all data is lost in the ListOfItemsFragment because FeedActivity is created again.
我应该为帖子的详细信息创建一个新的Activity,还是应该向FeedActivity中添加另一个独立于ViewPager的片段(我希望该片段是一个弹出窗口,而不是选项卡的一部分).
Should I create a new Activity for the post detail, or should I add another fragment to FeedActivity independent of ViewPager (I want this fragment to be a popup, not a part of the tabs).
我如何支持这种行为?
谢谢.
推荐答案
每次按回该新的Activity实例都将被创建.填充填充数据的擦除.只需在清单文件中键入以下几行即可.
Every time you press back the new Activity instance is created. Hense filled data erases. Just type the following lines in manifest file.
<activity android:name=".MainActivity"
android:launchMode="singleTop">
</activity>
这篇关于活动更改时将数据存储在片段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!