Fix unused new stack when bring existing activity to front
If a non-top reusable activity is found when starting activity on
secondary display, the condition in
ActivityStarter.setTargetStackAndMoveToFrontIfNeeded will get launch
stack by the reusable activity. But it actually creates a new stack
with the target display which won't be used and seems as a leakage.
That may also disturb focused stack checking when it is on the top of
display (e.g. other tasks are moved to back).
This change gives the preference to use the stack of candidate task
if it already exists on target display. Then it will have the same
behavior as default display that reuses the existing stack.
Bug: 117799939
Test: atest ActivityStarterTests#testBringTaskToFrontOnSecondaryDisplay
Change-Id: I65213386d9802f39ac7ba0d377a06711913c672d
3 files changed