活动之间的切换在Android的? [英] Switching between activities in android?

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

问题描述

在我的Andr​​oid应用程序中,我有以下的要求。

In my android application, I have following requirement.

活动A - >活动B(去选项) - >活动C(去一个选项,请转到B选)

Activity A --> Activity B(Go to A Option) --> Activity C(Go To A Option,Go To B Option)

1)去从b活动我已经使用活动A onBack pressed()方法。

1) To Go To Activity A from Activity B i have used onBackPressed() method.

2)去从活动三我已经使用b活动 onBack pressed()方法了。

2) To Go To Activity B from Activity C i have used onBackPressed()method again.

这是工作的罚款。

3)现在我想去的活动C(活动一个没有意图调用)。

3) Now i want to go to Activity A from Activity C (without Intent calling).

我怎样才能做到这一点?

How can i do this?

编辑1:

活动A是我的主要活动我不想用Intent.i要恢复活动一个从活动c。重新启动该活动。(就像我从b活动确实使用onBack pressed)。

Activity A is my Main activity i don't want restart the activity by using Intent.i want to resume Activity A from activity c.(like i did from activity B by using onBackPressed).

编辑2(附答案):

好球员。在我的question.finally给我的帮助,谢谢大家,我发现类似@Paresh Mayani的回答一个简单的答案。

Ok guys. Thanks everyone for giving me your help on my question.finally i found a simple answer similar to @Paresh Mayani's answer.

答:

        Intent a = new Intent(getApplicationContext(),ActivityA.class);
        a.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(a);

我用这个<一个得到这个很好的解决方案href="http://stackoverflow.com/questions/8688099/android-switch-to-activity-without-restarting-it">link这解决了我的问题。感谢大家再次,我真的AP preciate了。

i got this nice solution by using this link that solved my problem. thanks to everyone again and i really appreciate that.

推荐答案

我以为你不想要的,因为当你使用意向的转向活性的pressing返回键移动到$ p来使用意向$ pvious活动(活动C)。在这种情况下,我建议你包括 FLAG_ACTIVITY_CLEAR_TOP 标志。它会破坏所有的previous活动,让你移动到活动一个。

I assume that you don't want to use Intent because whenever you use Intent for moving to activity A pressing Back key will move to the previous activity (activity C). In this case I would suggest you to include FLAG_ACTIVITY_CLEAR_TOP flag. It will destroy all the previous activity and let you to move to Activity A.

 Intent a = new Intent(this,A.class);
 a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 startActivity(a);

另外,您也可以尝试 FLAG_ACTIVITY_REORDER_TO_FRONT 标志来代替,这将移动到活动一个不清除任何活动。

Alternatively, you can try the FLAG_ACTIVITY_REORDER_TO_FRONT flag instead, which will move to activity A without clearing any activity.

有关更多详情,请

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

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