Android 12 — Back Press On Launcher Activity

Swatiomar
3 min readDec 24, 2021

An Investment in knowledge pays the best interest.
- Benjamin Franklin

As we’ve discussed about Android 12 Behavior Changes for Splash Screen in previous article , Now, Today we’ll talk about Activity Lifecycle changes.

In Android 11 or lower versions, when we press back from launcher activity, the system finishes the activity. But from Android 12, launcher activities are no longer finished on Back press because it changes the default handling of the system Back press that are at the root of launcher activity’s tasks.

What does mean by root of Launcher Activity’s tasks?

Activities that declare an Intent Filter with both action.MAIN and category.LAUNCHER.

What changes are made in Activity Lifecycle?

To understand the changes in Activity Lifecycle, Let’s take an example. I have a Main Activity which is in Launcher Activity category with action Main define in AndroidManifest.xml file.

  1. Launch the app, Lifecycle methods are:
On Launching The App

2. Now press Back Button,
In Android 11 and lower versions,

On Press Back Button : Android 11 and lower versions

In Android 12,

On Press Back Button : Android 12

3. Now, launch the app again,
In Android 11 and lower versions,

On Relaunch the app : Android 11 and lower versions

In Android 12,

On Relaunch the app : Android 12

In a nutshell, In Android 12, System now moves the activity to the background instead of finishing it, just like when press home button or gesture. By this change, users who navigate out of your app, now resume app quickly from a warm start instead of cold start. If you’re having confusion regarding warm start and cold start, please go through previous article.

Happy Coding :)

I hope you liked the article. Feel free to share any feedback. And stay tuned for more concepts!

Don’t forget to follow me on Medium. If you liked the article, click the clap below so more people can see it!

Thanks !!!

--

--

Swatiomar

As a programmer, to keep learning and help ones who needs the skills to be a master, I am available to be a part of an adventurous journey….