I have an application with activities back stack A -> B -> C -> D -> E. Now at activity E, I want to know the back stack activities that I navigated from. How do I find this??
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I recommend you to utilize startActivityForResult instead of startActivity, then in order to retrieve the origin/source activity- call getCallingActivity().getClassName().
How will A know it came from home? Use getIntent() its getAction() -> android.intent.action.MAIN and getCategories() -> android.intent.category.LAUNCHER
actually, you can get the task id from the runningtaskinfo using getRunningTasks and then, get the recenttaskinfo using getRecentTasks by compare the task id. now you can restart that activity using startactivity, with the baseintent in the recenttaskinfo.
You can use "adb shell dumpsys activity activities" command
for reference http://www.onsandroid.com/2015/01/find-back-stack-activities-in-android.html
The code below can be used to extract all the tasks and the top activity within each task in the back stack
I'm not sure i get it well...You want to go back to the previous activity ? If so, finish the current activity you'll get back to the previous one.
As
getRunningTasks(..)
has been deprecated or if you don't want to add special permissions to your app here is an alternative solution if all activities are yours: you can mark an identifier (not the activity itself is it may be in need to be garbage collected) in a singletonStack
,LinkedList
orLinkedHashSet
: inonPause()
add the identifier to the stack and remove it inonResume()
.You can check the contents of that stacks to know if there is any activity and the sequence they have been created.
You can clean up your code and forget to do that manually if all your activities derive from a common base activity for your app.