简体   繁体   English

从通知开始另一个活动之前,先完成一项活动

[英]Finish an activity before starting the other one from notification

I've implemented OneSignal push notifications in my Android app. 我已经在Android应用中实现了OneSignal推送通知。 I'd sending push notifications with URL as a payload attatched to them. 我将发送带有URL的推送通知作为附加到它们的有效负载。 That URL sends an intent that can be opened by another activity of my app or the browser. 该URL发送的意图可以由我的应用程序或浏览器的其他活动打开。 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. 因此,当我的应用程序的某些活动处于前台状态并且我选择在我的应用程序中打开通知时,我的应用程序有2个实例。 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. 另外,我尝试了所有启动模式: normalsingleTopsingleTasksingleInstance ,都产生了它们设计的结果,但是没有一种适合我的情况。

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. 它将清除前台活动实例,并在顶部创建新的活动实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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