A long introduction to Kotlin Coroutines
The basics of Coroutines, the major building blocks, and a simple overview of the framework
If you ever created an app that has more than 2 activities, it’s likely that you needed to change the launch mode for some of them. I must admit that the whole thing is still a bit confusing to me… Normally, I need to visualize everything in order to fully understand what happens – that’s what I was going to do with the screen navigation back stack too. There was a lot of information online already (also a lot of useless stuff, heh) but eventually I decided to create a simple app to demonstrate how activity stacking actually works and what happens inside.
On to the main point.
The app shows the activity title on top of each screen, describing what kind of activity you’re currently looking at. It also displays that activity’s Intent origin (where it was started from). Next to it, each screen also shows the current activity’s task ID, and the corresponding task ID from the origin activity.
Below all of that, there’s a list of currently active tasks from the OS – or, at least the tasks we could access using the new API) – so that you can see exactly what happens when you switch to another activity. You should only be interested in the launcher task and your app’s tasks and ignore the other ones.
To change/switch/go to another type of activity, just use one of the buttons at the bottom, options are:
singleInstance. You can read more about the tasks and back stack from the official docs, or take a look at this explanation video presented by Google’s team.
To illustrate what I detected during this task and backstack experiment, I created a video using the app mentioned above and going through various scenarios, recording all of that and then wasting a few hours on preparing the output. Warning: there’s some irritating background music I couldn’t get rid of. 😬