Android: access the Activity stack programmatically

丶灬走出姿态 提交于 2019-12-07 05:09:53

问题


is it possibile to get the current Activity stack from code?

Here is my use case:

  • the user navigates from Activity to Activity

A -> B -> c -> D -> ...

  • some of the Activity will finish after sending the user to the new screen, some others won't

  • I need to check if pressing the BACK button will bring the user to the Activity A or any other because in the currently shown Activity I have a button that finishes the Activity and the icon of the button is different weather you'll be taken to tha Activity A or another Activity.

Thanks in advance,

Bye, Maurizio


回答1:


My impression is that the answer to the literal question is "no" - you cannot access that. But there's probably another way to accomplish what you need.

If these are all your activities, why not put an extra in the Intent (when going in the forward direction) which says which activity it is coming from.

You can then decide which back button image to display based on checking that extra, which should tell you what the previous activity was (if it was one of yours - if it's empty you have to assume it came from somewhere else in the system)



来源:https://stackoverflow.com/questions/10351688/android-access-the-activity-stack-programmatically

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