安卓活动backstack管理 [英] android activity backstack management

查看:129
本文介绍了安卓活动backstack管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序显示了一些内容(视频,PDF,IMG等),每一个内容中我可以启动另一个内容。我要的是只具有一回的历史。

My app shows some content (video,pdf,img, etc ) and within every content I can start another content. What I want is to have only "one back history".

例如,如果我的活动历史是这样的: VideoActivityIns1-> PdfActivityIns1-> VideoActivityIns2

For example, if my activity history is like this: VideoActivityIns1->PdfActivityIns1->VideoActivityIns2

我要回去从VideoActivityIns2到PdfActivityIns1,但退一万步就是应该是我的应用程序的MainActivity。

I need to go back from VideoActivityIns2 to PdfActivityIns1, but one step back is should be MainActivity of my app.

我怎样才能做到这一点?任何帮助将是AP preciated

How can I do this? Any help would be appreciated

推荐答案

每个活动都有活动的生命周期方法,你可以重写,以达到你所需要的结果。这样,你可以发动活性2 onResume()在活动1的onPause()

Each activity has activity lifecycle methods you can override to achieve the result you need. Thus, you can either launch Activity2 onResume() on Activity1 onPause(),

http://developer.android.com/training/basics/活动的生命周期/ index.html的

,或调用ActivityManager检测和管理等活动。

or, invoke ActivityManager to detect and manage the other activities.

http://developer.android.com/reference/android/app/ ActivityManager.html

您还可以使用意图解决机制,在每个活动指派多个优先级的活动,然后设置意图过滤器,所以你可以在你的code开始与优先活动。你可以做到这一点无论是在Java或XML(虽然我认为Java的)。看一看Intent类。

You can also make use of intent resolution mechanism to assign several priorities to your activities and then setup intent filters in each activity so you can start activities with a given priority in your code. You can do this either in Java or XML (though I suggest Java). Have a look at the Intent class.

这篇关于安卓活动backstack管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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