How do I only have one task in my application?

276 Views Asked by At

This is my Main Activity in Manifest:
Manifest
And I has Receiver to detect my app is replaced(re-install)
onReceive
re open app
After detect re-install, I re-open app but has issue -Whenever press Home then click icon app to open, always create new task and old task is not removed
=> My expect is open old task, when press Home key then click icon app Plz help me resolve it! Thank you!

1

There are 1 best solutions below

1
On

Set the launchMode on the Activity in your manifest to be singleTask. This will make it so that if an existing Activity exists when you try to launch it, it will find it and call its onNewIntent instead of creating a new instance.

Please note that this will only work if the framework hasn't destroyed the old activity for resources yet. Which is unlikely if you quickly go back to that app, but can happen if you take a long time or open resource intensive apps.