My application has three activities say A -> B-> C
.
Activity A is called from another activity through startActivityForResult()
. Activity B and C are also called similarly. I have to call activity A from notifications bar also (if there is some specific notification).
Now, if currently I am in activity B or C, and I click on Notification bar, and call the activity A, the app goes to Activity A only and data entered through activites B or C do not persist.
I don't want such behavior. I want that if I click on Notification, it should redirect to current screen only. Can some one help. (I mentioned activity:launchMode
as SingleTask
).
Using android:launchMode="singleTask"
is probably the best approach, since it won't recreate the activity if it's already running. Just add it to the activity in your AndroidManifest.xml, and you should be all set.
<activity
android:name=".MyActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Here's another question that might be useful: Android singleTask or singleInstance launch mode?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With