A. Whats the most elegant way to have an android M notification bring an existing target activity from the back stack to the top (i.e. not create a new target activity instance on top), while keeping the remaining back stack intact, under the following two scenarios:
- Task with target activity is in the foreground
- Task with target activity is in the background
B. If A is not possible, whats the most elegant way to have the notification
- Just continue showing the task with its stack intact if its already in the foreground (i.e. not create a new target activity on top)
- Bring the background task to the foreground intact without creating a new target activity instance on top.
This is like (re)launching the app from its icon on home screen or app drawer.
C. If B is also not possible, whats the most elegant way to have the notification perform B, and then create a new target activity instance on top EXCEPT when the target activity is already on top.
I don't think its pertinent, but the notification is set from a foreground service.
This question has been asked in various forms earlier and has received many answers. However APIs have changed, what worked earlier no longer does, most answers are many years old, answers are quoted from docs which sometimes don't follow practice, terminology used in those QnA are wrong and add to overall confusion, and on top of that some accepted answers are just plain wrong (e.g. this thread). Further, the behavior is quite complex given the many different scenarios that can occur and after having read pretty much all QnA on this topic, I didn't find sufficient engineering preciseness in those.
Also It's OK to Ask and Answer Your Own Questions is encouraging!
I'm going to start documenting my findings as answers to this question.
Answers, comments, corrections most welcome, only if its a proven mechanism for Android M, API 23 only. Please mention whether its for A, B or C. Dont want to go off on any more wild goose chases ;-)