onDestroy()
is not always called. If called, only part of the code is executed. And most of the time in LogCat I only see the message "gps state on destroy called first". Why is that?
protected void onDestroy() {
super.onDestroy();
Log.d("on destroy called", "gps state on destroy called first");
editor.putBoolean("gpsOn", false);
Log.d("on destroy called", "gps state on destroy called second");
editor.commit();
Log.d("on destroy called", "gps state on destroy called third");
stopRouteTracking();
Log.d("on destroy called", "gps state on destroy called fourth");
}
onStop
instead ofonDestroy
?onStop
is called right beforeonDestroy
. And, also,onDestroy
shouldn't run codes that might take a lot of time. – Licensesuper.onDestroy()
to the last line of the method. – Calcareous