2

I am trying to create a mock location app. After the user chose a location, the app should spoof his location to the place he chose.

I want that when the user closes the app, from recent apps or by pressing the back button the app will stop to mock location.

After reading the docs and some debugging, I understand that the OnDestroy function does not get called when the user stop the app from recent apps.

How can I know when the user decided to kill the app?

1 Answers1

0

Yes, there is no guarantee that onDestroy method will be called everytime.onDestroy is called when Android goes short of resources and it need to clean up to recover some memory resources.

So, the best solution is to properly use onStop callback for deleting the location reference and initilize again in onStart.

For more details, check following links: https://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29

Activity OnDestroy never called?

Community
  • 1
  • 1
Ani
  • 1,041
  • 6
  • 15
  • This won't help me, because the user needs to go to some other apps when he spoofs his location, his spoofed location needs to stay on onPause. In this case onStop will be called and it won't help me. I want to know only when the user kill the app. –  Jun 29 '16 at 00:51
  • Then why can't you use SharedPreference or some Singleton Class to hold the location for some time. – Ani Jun 29 '16 at 01:42
  • How will SharedPreference or some Singleton Class help me? –  Jun 29 '16 at 11:03