Sitemap

Instance Wars: When Activities Multiply and Tasks Collide

3 min readJun 16, 2025

--

Get a deeper understanding of instances, tasks, activities, and the back stack

Have you ever wondered how your Android app keeps track of which screen to show next or how it remembers where you left off? In this issue, we’ll break down two key concepts that make this possible: instances and tasks. These are fundamental to how Android displays screens and keeps track of your navigation journey.

📱Instances

In Android, each screen is typically represented by an Activity, which is an instance of a class. If you are familiar with classes in object oriented programming then you know that an instance refers to a specific object created from a class. The object is made from a class in your codebase. In Android development it is the same, but in our context an activity is an instance of a screen in your app or there can be multiple instances of your app opened depending on your launchMode in your AndroidManifest.xml file.

🗂️Tasks

A task is a collection of activities that users interact with when using your app. These activities are arranged in something called a backstack which keeps tracks of the activities open in order. You can think of it as a stack of cards where each new screen (activity) is placed on top of the stack. 🃏 When the user presses the back button, the top activity is popped off, and the one underneath is shown. It follows the last-in first-out rule for stacks. With this stack, the app can keep track of where you are in the app and correctly navigate back to a certain screen by popping the current screen off the stack to show the next most recent screen.

🖇️Together

Each task has its own back stack, and new activities can be added to it as the user navigates through the app. Now you can have multiple tasks in your app which each can have its own set of activities and a back stack as well. This ties in with the previous article of launchModes and the behavior of activities and tasks. In the last newsletter, we touched upon singleTop and singleTask.

Get Vanessa Johnson’s stories in your inbox

Join Medium for free to get updates from this writer.

When it comes to singleInstance, there is only one instance in its own task. The system will not launch any other activities into that specific task so any activities that are started from that first one will open in a separate task. So be mindful of how you want to structure your app.

As for singleInstancePerTask (available in Android 12+) the activity can only run as the root activity of the said task. The activity can be started/exist in multipleinstances in different tasks depending on the intent flags you set. You can think of intent flags as metadata for your intent. They will instruct the Android system on how to launch an activity.

⚠️Keep in mind that singleTask and singleInstancePerTask both clear the backstack so you will not have the history/ ordering of activities that may be needed for backward navigation. 🧭

That’s a wrap for today! I hope this gives you a clearer picture of how Android handles navigation through tasks and instances. Got questions? Drop them below — I’d love to help. And don’t forget to subscribe to my newsletter where posts go out earlier and this was first published. Also share this with fellow Android devs. Something exciting is coming in the next issue, so stay tuned! 🥳

--

--

Vanessa Johnson
Vanessa Johnson

Written by Vanessa Johnson

Your weekly source for actionable insights, expert tips, and career strategies for Android engineers.