سؤال

I have a very specific situation (required by a client) that has me having problems with the navigation, I gotta admit that I haven't handled Tasks before this project, and I might be missing something a bit obvious.

Let's say I have activity A (main) that starts B. The thing is, a BroadcastReceiver triggers an activity B (I know it's not recommended but it is one of the hard requirements) which needs to use FLAG_ACTIVITY_NEW_TASK.

What happens is, I'm at the new B, and once the user enters a code, activity A will be prompted, if a press back there, I'll return to the original task if it was backgrounded, which has A->B. Leading to something like A->B->(background/home button). BroadcastReceiver->B->A->(back to old task of A->B)

Is there a way to get rid of that task or at least force the new activity A to be the one of the original stack so the user can go to the home screen once back is pressed?

I have checked this post but the suggestions didn't help.

Min API level 9.

Thank you in advance, and believe me, I've tried many launchMode combinations and read many many posts. Thank you once more.

هل كانت مفيدة؟

المحلول

Just in case anyone get's to this point. There was a modification in the source code a few weeks ago that had the Main activity to be finished, therefore, the launchMode singleTask was not taking any effect when it came to reusing that activity and clearing the upper part of the stack via CLEAR_TOP flag. Hope anyone that comes to a similar problem checks the code to that point since navigation (util) libraries were used. Keep tabs on that.

Thus:

This was happening. A started B while finishing itself, leading to a stack of just B. After the BroadcastReceiver-extended class started A there was no previous activity A in any of the tasks' stacks. Which created task1[B] task2[B] task2's B started A and after task2 is finished, it would go back to task1 with B which would in turn recreated A when Up button was pressed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top