Shuyun6
Shuyun6

Reputation: 191

How an Activity is killed by Android?

As we know Android would kill a paused Activity in some conditions. And there is a FIFO back stack of Activities.

My questions are as follows:

  1. How Android kills an Activity without pulling it from the back stack (it might affect the top active Activity)

  2. After killing it, what things are released from this Activity? And can I still get this Activity's instance?

Upvotes: 1

Views: 1692

Answers (3)

Onik
Onik

Reputation: 19959

Android does not kill Activities "separately", it kills the whole app process with all Activities.

The only way to get an Activity killed by the system is to set Don't keep Activities flag in device's Developer Options. However this option is just for development, not for applications in release.

Upvotes: 1

Said
Said

Reputation: 689

System can't kill activity, it can call the whole app.

And when it kills the whole app, it doesn't call any method from activity (onStop(), onDestroy(), etc)

Finally, you can't get activity instance.

Upvotes: 1

Rezaul Karim
Rezaul Karim

Reputation: 880

Activity can't be killed but Os can kill the whole application. In this case you can try finish()/finishActivity()/context.finish() to finish the activity. While you finish an activity backpress will not return to the previous activity.

Upvotes: 1

Related Questions