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

advertisements

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.