维护 TabGroupActivity 中子活动的状态
我已按照此教程来完成我的应用程序。
我有: 选项卡 1: Tabgroupactivity1>(startchildactivity)MainActivty>(startchildactivity)ListActivity>(startchildactivity)DetailActivity
类似地,我还有其他两个选项卡。
问题是,当我从以下任何活动返回到上一个活动时,它(上一个活动)将重新启动。
我也尝试过使用 SINGLE_TOP 和 SINGLE_TASK 启动子活动,但在这个只有一次我可以完成流程
第二次它不会调用以下(下一个/子)活动
所以当它要求子活动并返回时,我如何保持当前的活动状态?
我正在使用 listactivty 的以下意图 onclick:
Intent myintent = new Intent(getParent(),Second.class);
myintent.putExtra("id",favadapter.getItem(position).id.toString());
TabGroupActivity parentFav = (TabGroupActivity)getParent();
parentFav.startChildActivity("FavActivity", myintent);
I have followed this tutorial for my application.
I have:
Tab 1: Tabgroupactivity1>(startchildactivity)MainActivty>(startchildactivity)ListActivity>(startchildactivity)DetailActivity
similarly I have other two tabs.
The thing is that when i Return from any of the following activity to previous one it(previous one) gets restarted.
I too have tried to startchild activity with SINGLE_TOP and SINGLE_TASK but in this only once I can go through the flow
second time it does not call following(next/child) activity
So How can i maintain current activty state while it calls for child activity and return ??
I am Using following intent onclick of listactivty:
Intent myintent = new Intent(getParent(),Second.class);
myintent.putExtra("id",favadapter.getItem(position).id.toString());
TabGroupActivity parentFav = (TabGroupActivity)getParent();
parentFav.startChildActivity("FavActivity", myintent);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上 TabGroupActivity 在 android 2.1 和 2.2 中存在问题,未正确从堆栈中删除的活动会导致我们的实例每次都重新启动。
为了克服这个问题,我们使用 SINGLE_TOP 和 SINGLE_TASK,即使它会导致另一个问题,只有一个实例运行而不是第二次,因为在子完成中我们这样做,
意味着它删除所有lastID意图并带来最新的一个,因为你的lastId(这是启动活动时使用
.startChildActivity("FavActivity", myintent);
) 对于多个实例来说是相同的。为了允许您的子活动第二次运行或运行多个实例,请使用动态意图 ID 启动子活动。
例如,
Actually TabGroupActivity have a problem in android 2.1 and 2.2 , the activities not properly removed from stack causes our instance to restart every time.
To overcome that issue we use SINGLE_TOP and SINGLE_TASK, even it cause another problem only one instance run not for second time because in child finish we did like this,
means it remove all lastID intent and bring the latest one, because your lastId (which is used while starting activity
.startChildActivity("FavActivity", myintent);
) is same for multiple instance.In order to allow your child activity to run second time or for multiple instance use Dynamic intent ID to launch child activity.
For example,