3

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.

3
  • what you wanna achieve by recreating the activity which can't be achieved through simple onactivityresult or in your onresume Commented Oct 1, 2016 at 17:30
  • @PavneetSingh I have code that executes in the onCreate that sends calls to a webAPI with the user's longitude and latitude. I want this to be executed again when I turn on GPS and return to my activity. Commented Oct 1, 2016 at 17:31
  • you should add your code Commented Oct 1, 2016 at 17:47

1 Answer 1

2

when you moved from activity to settings then, Activity will go to onStop(). So, you can call onRestart() method in onStop() method will resume your Activity. Hope this option will help.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.