Java – Recreates Android Activity on popping from the return stack

Recreates Android Activity on popping from the return stack… here is a solution to the problem.

Recreates Android Activity on popping from the return stack

I

have an Android activity that checks if the user’s GPS is on, and if it’s off, I have the option to go to Settings to turn it on. However, when I return from setup and pop my activity from the return stack, I want onCreate() to run again and execute the code using my location. I’ve tried running recreate() inside the onResume() method, but in that case it won’t load my activity at all.

Any suggestions on how to perform this task are welcome. Thank you.

Solution

When you move from Activity to Settings, the Activity goes to onStop(). Therefore, you can call the onRestart() method in the onStop() method to resume your activity. Hope this option will help.

Or, if this link is your case, then you can find the answer on the same page.
How can I return back to my Activity from GPS settings window

Related Problems and Solutions