Right now I'm using a PendingIntent
to launch my desired Activity
from the Notification
. But I want to know if it's possible to reuse the current app instance.
For example:
- Launch app, the Launcher Activity is called
HomeActivity
- Navigate to
SecondActivity
- Press the home button
- Click on the notification from the app and resume
SecondActivity
But if the user didn't navigate to the SecondActivity
i want to open the HomeActivity
when I click on the Notification. I would be glad for any help regarding this problem :)
Yes, you can reuse if the app is in background. In PendingIntent you will pass an Intent, so in that Intent you should set a flag like
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
so if the app is in background it will just bring activity to front.According to android docs :
Check the docs here
Why do you launch HomeActivity if your notification intent class you are creating have SecondActivity as the launcher. It will create a new SecondActivity and launches it if it is not in background.
EDIT:
If you want to relaunch app where you left off try like this :
Here
YourLauncher.class
is the launcher class name.