android activity backstack management

余生长醉 提交于 2020-01-06 13:30:03

问题


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".

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

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

How can I do this? Any help would be appreciated


回答1:


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/activity-lifecycle/index.html

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

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

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.



来源:https://stackoverflow.com/questions/20953799/android-activity-backstack-management

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!