Describe the back stack for A to B to C with singleTask

Tests singleTask plus taskAffinity, not rote memorization. With default affinity, C sits atop B in the same task; if C already existed, the system clears B and delivers onNewIntent. Red flag: claiming singleTask always spawns a new task.
What's really being asked
Whether you understand that singleTask behavior is governed by taskAffinity, not just the launchMode attribute alone. Many developers memorize that singleTask creates a new task, but the real behavior depends on whether the activity shares the current task affinity. The interviewer wants to see if you can explain stack manipulation, instance reuse via onNewIntent, and the difference between first launch and re-entry.
The full answer
Four points in order. First, because A, B, and C share the default taskAffinity in the same application, launching C from B places C on top of the current task; the back stack becomes A, B, C. Second, if C already existed somewhere in the back stack, the system would clear every activity above it, including B, and route the intent to the existing instance through onNewIntent; the stack would collapse to A, C. Third, if C had been assigned a different taskAffinity, the system would either create a new task with C at the root or bring an existing matching task to the foreground. Fourth, only one instance of a singleTask activity can exist system-wide within its affinity scope, so the activity is never duplicated.
The mistakes people make
Claiming that singleTask unconditionally creates a new task regardless of affinity. Saying that the stack always clears above C even on the first launch. Describing singleTask as identical to singleTop. Forgetting to mention onNewIntent when an existing instance is reused. Asserting that pressing back from C would always return to B without acknowledging the new-task edge case.
What usually comes next
What happens if the user presses back from C when it is in a new task? How does singleTask differ from singleTop? What if the intent contains FLAG_ACTIVITY_CLEAR_TOP or FLAG_ACTIVITY_NEW_TASK? How would you debug an unexpected task stack in the Recents screen? What happens to activity lifecycle callbacks for B when C clears it from the stack?
A concrete example
Imagine a music player Activity declared as singleTask. From a playlist screen B, the user taps a song that launches player C. With default affinity, C sits on top of B in the same task. Later, a notification tap tries to reopen the player. Because the singleTask instance already lives in the task, the system delivers the new track URI via onNewIntent and pops any screens above C, ensuring the player remains the sole instance and the user returns to it without duplicate activities.
Interview question
Activity C is declared singleTask and shares default taskAffinity with A and B. When B launches C for the first time, what is the resulting back stack?
- a.The system clears B and delivers the intent to an existing C via onNewIntent
- b.C launches into a new task because singleTask always creates a separate task
- c.C is placed on top of B in the same task, giving A, B, CCorrect
- d.C behaves like singleTop, creating a new instance unless it is already at the top
Why? this is the answer
With matching taskAffinity, singleTask places C on top of the current task on first launch, yielding A, B, C. Option B is wrong because singleTask only spawns a new task when the affinity differs, not unconditionally.
Just read this? Test yourself on what you have been reading.
Read the original → developer.android.com
- #android
- #activity-lifecycle
- #launchmode
- #back-stack
- #task-affinity
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles