Photo by Hal Gatewood on Unsplash

The Heisenbug that had us baffled for days: The strange tale of tasks and launch intents

Jun 4, 2018 · 3 min read

The app forgets its state when started from the app drawer.

Once upon a time…

The way launch intents should work

This is how a simple app with main and detail activities should be resumed from the launcher.

The way launch intents falter

Unfortunately, this is the reality of how tasks are resumed from the launcher: a new instance of the launch activity is created.

Upon each launch, MainActivity will appear as another new instance on the back stack.

Why should I care?

What can I do?

override fun onCreate(savedInstanceState: Bundle?) {
// Check that the activity was launched correctly
if (!isTaskRoot
&& intent.hasCategory(Intent.CATEGORY_LAUNCHER)
&& intent.action == Intent.ACTION_MAIN) {
// This activity doesn't belong

More details


The Creative Tech Agency


Written by

The Creative Tech Agency


The Creative Tech Agency