Andrej Naumovski Andrej Naumovski - 1 year ago 153
Java Question

Recreate Android activity when popped from back stack

I have an Android activity which checks if the user's GPS is turned on and gives the choice to go Settings to turn it on if it's off. However, when I return from Settings and pop my activity from back stack, I want onCreate() to run again and execute code which uses my location. I have tried running recreate() in the onResume() method, however in that case it will not load my activity at all.

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

Answer Source

onCreate is called just one time. The code you are using in onCreate, move to onStart.

Activity lifecycle

Read more about Activity lifecycle.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download