简体   繁体   English

从正在进行的通知中恢复Android应用

[英]Resuming Android app from an ongoing notification

I am working with notifications for the first time, and it seems that i must be missing something obvious. 我是第一次使用通知,似乎我必须遗漏一些明显的东西。 I have an Android app that plays music. 我有一个播放音乐的Android应用程序。 While it is playing, I have an ongoing notification displayed so I can easily get back to my app if it is in the background. 在播放时,我会显示持续通知,以便我可以轻松返回我的应用程序(如果它在后台)。 My problem is that when I click the notification, it opens a whole new instance of the application, instead of resuming the previous instance. 我的问题是,当我单击通知时,它会打开一个全新的应用程序实例,而不是恢复以前的实例。

I have a PendingIntent set up to launch my app, and a call to PendingIntent.getActivity(context, 0,myIntent, 0) I've tried different settings for the last parameter, but same results. 我有一个PendingIntent设置来启动我的应用程序,并调用PendingIntent.getActivity(context,0,myIntent,0)我已经为最后一个参数尝试了不同的设置,但结果相同。 What am I missing? 我错过了什么?

Mark D. 马克D.

You should edit your Activity's entry in the AndroidManifest.xml to include android:launchMode (see here for the options). 您应该在AndroidManifest.xml编辑Activity的条目以包含android:launchMode (请参阅此处了解选项)。 Most likely will be anything but standard . 最有可能是standard东西。 Also see if playing around with this and or this may help. 另外看看是否玩这个和/或可能会有所帮助。

我目前使用(在我的倒计时应用程序中):

android:launchMode="singleTask"

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

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