Note that there are some explanatory texts on larger screens.

plurals
  1. POReinstall / Update application what happens to a running service?
    text
    copied!<p>I have database cleanup that I need to do within a running service thread. Under normal conditions, this will occur when the service is done and onDestroy() gets called.</p> <p>I've noticed that if I reinstall or update the application while the service is running that onDestroy() is not called for the service. Is there anyway my application can know at the next startup that it's the first run after a reinstall so it can complete some cleanup on the database?</p> <p>To clarify, simply running the service again won't do what I need. My service in many cases is started by a broadcastreceiver and not by the activity itself so I can't rely on the onPause for the main activity. I can't figure out how to know if the service might already be running or was silently killed and needs cleanup.</p> <p>I'd like to clarify since others seem to have misunderstood. First, onDestroy just plain doesn't happen in the situation of a reinstall or update of the app. Neither do the shared preferences get reset because the app was not uninstalled. Second, Google specifically states you can't rely on the onDestroy, so berating me for finding a quick fix instead of asking Google why onDestroy isn't working doesn't quite make sense either. See the API docs about <a href="http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29" rel="nofollow">onDestroy</a> for Activities. The service documentation doesn't repeat that warning but obviously it holds true. The only working solution I've found to date is the one I posted below from another StackOverflow thread.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload