Understanding Android Activity Lifecycle (Part Four)

1. when the user close the application forcefully
2. when Android it self destroy the Activity.
3. when user hits the back button

Unfortunately you can not distinguish between 1 and 2.

But you can do something when user clicks the back button since onPause() is called after onBackPressed(),
so you can put a flag in the onBackPressed(). That way you can distinguish how it landed here

onBackPressed() -> onPause() or

home button / multitask button -> onPause()

Enjoy 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s