Questions tagged [ondestroy]

Tag for questions related to Android's onDestroy() method of Activities and Services.

The onDestroy() method is one of the lifecycle methods for Activities and Services on the Android platform. This method is the last method to be called before an Activity or a Service is killed. More information about this method can be found at the links below:

326 questions
430
votes
8 answers

Android activity life cycle - what are all these methods for?

What is the life cycle of an Android activity? Why are so many similar sounding methods (onCreate(), onStart(), onResume()) called during initialization, and so many others (onPause(), onStop(), onDestroy()) called at the end? When are these methods…
Nav
  • 9,588
  • 17
  • 52
  • 80
163
votes
13 answers

What is Activity.finish() method doing exactly?

I'm developing android applications for a while, and followed a lot of posts about activity life cycle, and application's life cycle. I know Activity.finish() method calls somewhere in the way to Activity.onDestroy(), and also removing the activity…
Tal Kanel
  • 9,855
  • 10
  • 55
  • 93
39
votes
2 answers

Android save state on orientation change

I've got an Android application which maintains state regarding distance traveled, time elapsed, etc. This state I can conveniently store in an object and store a reference to that object in the Bundle when Android calls onDestroy() when the user…
Intervention
  • 516
  • 1
  • 4
  • 8
38
votes
3 answers

Activity's onDestroy / Fragment's onDestroyView set Null practices

I am reading ListFragment source code and I see this implementation: ListAdapter mAdapter; ListView mList; View mEmptyView; TextView mStandardEmptyView; View mProgressContainer; View mListContainer; CharSequence mEmptyText; boolean mListShown; /** …
user3078555
33
votes
3 answers

Android Activity onDestroy() is not always called and if called only part of the code is executed

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(); …
ksu
  • 812
  • 1
  • 11
  • 17
30
votes
3 answers

Activity OnDestroy never called?

I am using following code in my ListActivity // a separate class in project public class MyActivity extends ListActivity { // some common functions here.. } public class SelectLocation extends MyListActivity { public void onCreate(Bundle…
UMAR-MOBITSOLUTIONS
  • 73,009
  • 94
  • 197
  • 273
29
votes
2 answers

What exactly does onDestroy() destroy?

I've been bothered by this "characteristics": When I use Back button to leave my app, I can tell onDestroy() is called, but the next time I run my app, all the static members of the Activity class still retain their values. See the code…
wwyt
  • 2,611
  • 4
  • 30
  • 42
27
votes
2 answers

android is there any view callback when it's destroyed?

I have a custom view component. I used it in either fragment or activity. I would like to know if there's a callback when it's destroyed from fragment/activity?
Shumin Gao
  • 547
  • 2
  • 7
  • 14
27
votes
4 answers

Fragments remain after Activity get's killed and recreated

I have a FragmentActivity (Support Fragments) where I create Fragments by code and put them into FrameLayouts. It all works fine so far. Now if I leave the App an return everything is fine as long as the system doesn't kill my Activity (or I do…
25
votes
3 answers

onDestroy gets called each time the screen goes on

My application gets killed each time that it comes back from the screen-off-state. I fetch all the information that my app does, but I can't find out why it calls onDestroy. It's the first time I'm seeing this behavior in my applications. My main…
mikepenz
  • 11,938
  • 14
  • 74
  • 112
25
votes
1 answer

When exactly is component destroyed?

In Angular 2 with Ahead-of-Time (AOT) compiling, I have a parent component and a child component, like this:

I am a parent

I know that the child template is inserted to the DOM…
gye
  • 1,114
  • 2
  • 12
  • 24
25
votes
4 answers

Android: OnDestroy isn't called when I close the app from the recent apps button

When we press this button We see the apps which we didn't close, like this But when we want to close an app from this screen (below image), the method onDestroy() isn't called, however the app is closed. I need to call onDestroy() when the app is…
Curio
  • 1,212
  • 1
  • 11
  • 31
25
votes
2 answers

Android: Will finish() ALWAYS call onDestroy()?

Simple question: can you be sure that finish() will call onDestroy()? I haven't found any confirmation on this.
Xander
  • 5,007
  • 14
  • 46
  • 76
23
votes
5 answers

How to make notification resume and not recreate activity?

I thought I had this figured out, but after some debugging on this question: How to make notification uncancellable/unremovable I just realized my activity is still getting onCreated() and onDestroyed(), in random order. My manifest for the…
CeeRo
  • 1,052
  • 3
  • 10
  • 20
22
votes
3 answers

Android app doesn't call "onDestroy()" when killed (ICS)

I'm developing an android app using bluetooth communication (using a propetary protocol) and I need to catch the moment when the app is killed. I wanted to use the "onDestroy()" method but it isn't called every time the app is killed. I noticed that…
The Good Giant
  • 1,560
  • 1
  • 18
  • 31
1
2 3
21 22