简体   繁体   中英

Finish an activity before starting the other one from notification

I've implemented OneSignal push notifications in my Android app. I'd sending push notifications with URL as a payload attatched to them. That URL sends an intent that can be opened by another activity of my app or the browser. So, when some activity of my app is in foreground and I choose to open the notification in my app, there are 2 instances of my app. So, even if a user taps Exit in the now top-most activity, the one that was already opened still remains. Basically, users have to exit twice from my app (and possibly more times if this keeps on happening).

So, is there any way by which I can finish the foreground Activity when the user taps on the notification (and chooses to open it in my app instead of the browser) and then proceed..?

Also, I have tried all the launch modes: normal , singleTop , singleTask and singleInstance , all produced the results that they were designed to, but, none could suit my case.

I don't know which code should I include here.

If this can't be done, is there any way to launch all activities of my app (no matter from where they're launched) into the same instance?

For this you will have to start activity from notification by using activity flag like this

yourintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

it will clear foreground activity instance and your new activity instance create on top.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM