简体   繁体   中英

Android - How to resume the last activity when launched icon is clicked or when back button is clicked

I am working on a tracking application that use another third party application such as google map.

Lets assume my application has 4 activities ( act1, act2 , act3 and act4 ).

on act3 activity i am calling google map application to calculate the distance and view the routing. But once i clicked on the back button of the tablet, or go back to the home page and clicked on the launched icon, the act1 is displaying instead of act3.

However, my application is still running on background.

So my question here how can i make the application is opened the last activity which is act3 in our example, when the back button is pressed or when the launched icon is clicked.

Thanks,

Store the name of the running activity into shared preferences in the onPause of every activity (if you're exiting by pressing home button) or in onBackPressed (if exiting an activity by pressing back button).

Then create a launcher activity which reads the shared preferences and launches the specific activity.

Lastly remove the launcher activity from the activity stack so that the app doesn't go back to it on pressing back button.

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