维护 TabGroupActivity 中子活动的状态

发布于 2024-12-21 19:43:18 字数 820 浏览 5 评论 0原文

我已按照教程来完成我的应用程序。

我有: 选项卡 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 技术交流群。

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

发布评论

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

评论(1

雨夜星沙 2024-12-28 19:43:19

实际上 TabGroupActivity 在 android 2.1 和 2.2 中存在问题,未正确从堆栈中删除的活动会导致我们的实例每次都重新启动。

为了克服这个问题,我们使用 SINGLE_TOP 和 SINGLE_TASK,即使它会导致另一个问题,只有一个实例运行而不是第二次,因为在子完成中我们这样做,

Intent lastIntent = manager.getActivity(lastId).getIntent();
        Window newWindow = manager.startActivity(lastId, lastIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
        setContentView(newWindow.getDecorView());

意味着它删除所有lastID意图并带来最新的一个,因为你的lastId(这是启动活动时使用 .startChildActivity("FavActivity", myintent); ) 对于多个实例来说是相同的。

为了允许您的子活动第二次运行或运行多个实例,请使用动态意图 ID 启动子活动。

例如,

Intent myintent = new Intent(getParent(),Second.class);
myintent.putExtra("id",favadapter.getItem(position).id.toString());
TabGroupActivity parentFav = (TabGroupActivity)getParent();
parentFav.startChildActivity("FavActivity"+System.currentTimemillis(), myintent);

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,

Intent lastIntent = manager.getActivity(lastId).getIntent();
        Window newWindow = manager.startActivity(lastId, lastIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
        setContentView(newWindow.getDecorView());

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,

Intent myintent = new Intent(getParent(),Second.class);
myintent.putExtra("id",favadapter.getItem(position).id.toString());
TabGroupActivity parentFav = (TabGroupActivity)getParent();
parentFav.startChildActivity("FavActivity"+System.currentTimemillis(), myintent);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文