开发者

android application always opens default home page when application comes in foreground

I have 15-20 activities in my application. I want when user clicks on the icon of my app on the homepage and the app is running in the background, user should always see the default screen. However, as per default android behavior users see the last screen that appeared before the application goes in background. I also do not want to lose the back feature capability. Is there any way to know if user is navigating in the same application or user has switched to other application and coming back to my app. I know we can use onpause() etc for this kind of t开发者_如何学编程hing but I have 15 activities and I want to do this change at one place and do not want to lose back button functionality?


Well in the onPause() of each activity you could either write to a shared preference file if it is the current activity running (and possibly save your backwards stack if you are using one to keep multiple backwards), then in each onResume you could switch intent to the main activity, which could then load up the shared data (either the one piece, or populate an ArrayDeque if you have a stack. ArrayDeque as opposed to Stack, because stack is deprecated, as it is based on the deprecated Vector.)

That might be a little messy, but might not be too bad (I would have to try it to really know).

good luck, I hope that helped. If not, I hope someone else can help.


You can solve that by adding a boolean and making true whenever the application goes to background. You can use the onPause() for this.

After that you would have to do the checking on each activity using that boolean and the onResume().

I know it's not the prettiest way but i think that this can do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜