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:

340 questions
19
votes
3 answers

How to distinguish whether onDestroy() is called as part of configuration change sequence?

In my Activity some external thing (service) need to be destroyed in onDestroy(). But I do not want this when configuration change happens (e.g. keyboard flips out) because it will be restored right away. So the question is: how to distinguish…
Mix
  • 3,081
  • 2
  • 17
  • 14
18
votes
1 answer

onDestroy() while "waiting" for onActivityResult()

I have an app with two activities: "A" and "B". "A" uses startActivityForResult() to spawn "B" i.e. it waits for "B". Now, assume that "B" is in foreground. Can the Android system destroy activity "A" without also destroying "B"? (If yes, then when…
Thomas Calc
  • 2,994
  • 3
  • 30
  • 56
16
votes
5 answers

Android - Unable to destroy activity after finish, caused by IllegalStateException: Can not perform this action after onSaveInstanceState

I have an activity in my app with 3 fragments. When a button is pushed on the first one, a method is called in the Activity that does some irrelevant stuff and then calls finish(). This triggers onPause() on the fragment, which does more irrelevant…
15
votes
3 answers

Android service onCreate is called multiple times without calling onDestroy

In my app, I use a service to communicate with our server. The Service spawns several message queue threads to deal with tasks with different priorities. This model has been used for about one year without big issues. However, recently, I found some…
SXC
  • 237
  • 3
  • 8
13
votes
3 answers

Is it safe to do all cleaning up in onDestroy?

More concretely: Is it safe to place the canceling of a task in onDestroy? Also, is it safe to use onDestroy for unregistering receivers and freeing up resources? My aim is to make sure that my task is canceled/destroyed when the Activity is…
12
votes
6 answers

Activity is getting destroyed while pressing the home button

In my application, when I press the home button the activity is going to onDestroy(). It suppose to be called onPause() method only right? Why it is happening so?
Kamalone
  • 4,045
  • 5
  • 40
  • 64
11
votes
1 answer

Angular2 ngOnDestroy, emit event

is it possible to emit a custom event on ngOnDestroy ? I tried, but it seems like it does not work... I basically need to know when a Directive is removed from the UI. @Output() rowInit = new EventEmitter(); @Output() rowDestroy = new…
jona jürgen
  • 1,789
  • 4
  • 22
  • 31
11
votes
5 answers

Android back button behaviour

Let's say we have a default, empty activity with default behaviour, launched with default intent flags. User presses back button on the device. The activity disappear... but how, actually? Is pressing back button behaving the same way like…
Sebastian Nowak
  • 5,607
  • 8
  • 67
  • 107
10
votes
3 answers

is there an Application::onDestroy() equivalent for Android?

Hi I am using the Application::onCreate to put my initialisation code of my app, but when waiting some time and starting other apps, I noticed the instance of the Application class gets created again... How to detect globally when Android is…
David
  • 1,842
  • 2
  • 21
  • 31
10
votes
4 answers

Save data in activity's onDestroy method

I'm writing a tasklist and have Project object, which holds all the tasks (and metadata). I use action log, so when tasks changes i do not save it immediately to database, just keep it in memory to dump in database on activity finish. Activity's…
ryabenko-pro
  • 728
  • 1
  • 7
  • 18
9
votes
1 answer

Android: Activity.onDestroy() is not called when Dalvik kills this Activity

I'm confused about Activity.onDestroy(). I need to free some resources when my Activity is destroyed, but it seems like onDestroy() is called just when i press "Back" key, but not when my Activity is killed by Dalvik. I tested it just by adding log:…
Dmitry Frank
  • 10,417
  • 10
  • 64
  • 114
9
votes
1 answer

Android - is onDestroy supposed to destroy the activity, its variables and free up memory

I have a bug in my code that made me think I don't fully understand the Android Lifecycle. Yes, I have read all the docs and looked at the diagrams, but they seem to talk only about when to save data, when the activity may loose focus or get killed.…
Alex
  • 319
  • 6
  • 14
9
votes
2 answers

mdDialog: catch the onClose event

I'm creating a mailbox in angular. And I would need to save the draft message when the popup to send a message closes. I know there are some alternatives: scope.$on("$destroy", function () { saveMessage() }); and:…
9
votes
1 answer

Android: Order of statements in onDestroy() method

If I override my main Activity's onDestroy() method in order to recycle a bitmap when the screen is rotated, should I call super.onDestroy() before or after myBitmap.recycle()? Does it matter?
prepbgg
  • 3,564
  • 10
  • 39
  • 51
9
votes
3 answers

Is ondestroy not always called?

I have put some cache cleaning code in onDestroy of my activity but most of the time the code is not executed unless I explicitly finish the activity via finish(). Edit: Just read onDestroy is called only with finish() or if the system is low on…
yeahman
  • 2,737
  • 4
  • 21
  • 25
1
2
3
22 23