简体   繁体   中英

Finished Activity starting up on resuming the app from background

I have a peculiar problem. I have an Activity A , from which, after user logs in, I finish Activity A and start Activity B . I have a RecyclerView in Activity B , which starts fetching the data from my database. Now the issue is that if within 2-3 seconds of starting Activity B , I put the app in background by pressing android's back button and then fetch the app from menu, my app is again displaying the already finished Activity A .

My launcher Activity is Main, where the app decides whether to open Activity A or Activity B based on whether user has already logged in or not. I tried changing order of activities and checking cache values etc, but I am totally stumped. Activity A is simply popping up on resumption.

Please let me know if anyone has idea as to why this might be occuring.

Whenever you press the back button, Android would assume you want to exit the app. So when you open the app again, it will start from the beginning.

By checking whether or not user has logged in, you can decide to show Activity A or B. Without being able to check your code, it's difficult to say where stops you doing that. One possible solution is that save user login status in SharedPreferences so you can check if user has logged in when the app starts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM