I have an Android application that contains two Activities
.
Activity A
has a button that launches Activity B
using Context.startActivity(Intent intent)
.
There is also a Notification
that opens Activity in the same way.
If I start B
from this notification and press back button - it just closes B
and does not shows A
like I go there with normal case.
Is it possible to force B
to bo back to A
if started from notification without history stack ?
Solution
As stefan and Paul Lammertsma mentioned, the best way is to start A
from notification and in A
create new intent with B
- but not in onCreate()
!
I dig this a bit and found that if I set in AndroidManifest
a new property for A
activity:
android:launchMode="singleTask"
there will be in A
activity called
onNewIntent(Intent intent)
And there we should checl if Intent
containst extra value passed from notification - and if so, then we call new B
intent.
Thank you both and good luck with it for next devs ;-)
I would suggest having the notification call Activity A (instead of B directly) with some flag in its extras bundle. In A's onCreate()
, check for the flag, and immediately launch Activity B. This will ensure that pressing back on B will return to A.
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