切换到其他活动时是否让活动在后台运行?

问题描述:

我要进行主要活动,而按钮要进行其他活动.当我去其他活动时,我的主要活动停止了.我将如何进行主要活动?

I have my main activity going and a button going to a different activity. When I go to the other activity my main activity stops. How would I keep the main activity going?

谢谢.

是的,您可以保持主活动运行.我的方法是使用"CHEAT".

Yes, you can keep your main Activity running. My way is use a "CHEAT".

例如,您的主要活动是A,在A中,我们有按钮btnA.单击此btnA将打开活动B.

Example your main Activity is A, in A we have button btnA. Click this btnA will open activity B.

您创建的标签栏包含2个包含A和B的标签.初始化标签栏后,调用

You create a tab bar with 2 tab contains A and B. After initialize tab bar, call

tabHost.getTabWidget.setVisibility(View.GONE);

隐藏该标签.因此,您只会看到可见的主活动.

to hide this tab. So you only see main Activity visible.

单击btnA时,只需将tabHost切换为B

When btnA is clicked, only need to switch tabHost to B

tabHost.setCurrentTab(1);//1 is index of Activity B

此问题&答案与您的问题相似.您可以参考它.

This question & answer is similar with your question. You can refer to it.

活动和子活动