jjzjj

startForeground

全部标签

android - 单独线程中的 MediaPlayer 与通过 startForeground() 在服务中运行

因此,我在单独的线程中播放音乐。如果我离开应用程序(onPause()、onStop()被调用等),音乐会继续播放,但最终——在打开其他应用程序并在它们之间切换之后他们然后回到主屏幕——我的应用程序被杀死了。没有崩溃,只有WINDEATH和processcom.myapp.androidhasdied在logcat中。显然,应用程序被系统销毁以回收资源是合法的。我的问题是:在主(UI)线程之外的线程中运行内容是否意味着它现在就系统而言具有较低的优先级?意思是,它是否比我在Service中运行媒体播放器甚至使用startForeground()使服务在前台运行更容易被杀死?任何想法或澄清

java - startForegroundService() 没有调用 startForeground(),但它调用了

我的Android服务中的Context.startForegroundService()没有调用Service.startForeground(),但我不明白为什么会这样。我的应用是做流媒体的,只有当你从前台通知暂停(变成普通通知),然后你把通知滑开,这是为了停止我的服务时,才会出现这个错误。这是调用startForegroundService、startForeground和stopForeground方法的唯一方法:privatevoidconfigureServiceState(longaction){if(action==PlaybackStateCompat.ACTION_

android - 如何使用 NotificationCompat.Builder 和 startForeground?

小问题:我正在尝试使用NotificationCompat.Builder类来创建将用于该服务的通知,但出于某种原因,我要么看不到通知,要么在服务应该被销毁(或停止在前台)。我的代码:@OverridepublicintonStartCommand(finalIntentintent,finalintflags,finalintstartId){finalStringaction=intent==null?null:intent.getAction();Log.d("APP","serviceaction:"+action);if(ACTION_ENABLE_STICKING.equa

android - IntentService 的 StartForeground

我有一个IntentService,我想通过持续通知让它保持粘性。问题是通知出现然后立即消失。该服务继续运行。我应该如何在IntentService中使用startForeground()?@OverridepublicintonStartCommand(Intentintent,intflags,intstartId){super.onStartCommand(intent,flags,startId);Notificationnotification=newNotification(R.drawable.marker,"Notificationserviceisrunning",S

android - 如何在不显示通知的情况下 startForeground()?

我想创建一个服务并让它在前台运行。大多数示例代码都有通知。但我不想显示任何通知。那可能吗?你能给我一些例子吗?有没有其他选择?我的应用服务正在播放媒体播放器。如何让系统不杀死我的服务,除了应用程序自己杀死它(比如通过按钮暂停或停止音乐)。 最佳答案 作为Android平台的一项安全功能,您不能在任何情况下,在没有通知的情况下拥有前台服务。这是因为前台服务比后台服务消耗更多的资源并且受到不同的调度限制(即它不会被杀死的速度),并且用户需要知道什么可能在消耗他们的电池。所以,不要这样做。但是,可能会有“假”通知,即,您可以制作一个透明的

android - 如何在不显示通知的情况下 startForeground()?

我想创建一个服务并让它在前台运行。大多数示例代码都有通知。但我不想显示任何通知。那可能吗?你能给我一些例子吗?有没有其他选择?我的应用服务正在播放媒体播放器。如何让系统不杀死我的服务,除了应用程序自己杀死它(比如通过按钮暂停或停止音乐)。 最佳答案 作为Android平台的一项安全功能,您不能在任何情况下,在没有通知的情况下拥有前台服务。这是因为前台服务比后台服务消耗更多的资源并且受到不同的调度限制(即它不会被杀死的速度),并且用户需要知道什么可能在消耗他们的电池。所以,不要这样做。但是,可能会有“假”通知,即,您可以制作一个透明的

android - 升级到 Android 8.1 后 startForeground 失败

将我的手机升级到8.1DeveloperPreview后,我的后台服务无法正常启动。在我长期运行的服务中,我实现了一个startForeground方法来启动在创建时调用的持续通知。@TargetApi(Build.VERSION_CODES.O)privatefunstartForeground(){//Safecall,handledbycompatlib.valnotificationBuilder=NotificationCompat.Builder(this,DEFAULT_CHANNEL_ID)valnotification=notificationBuilder.setO

android - 升级到 Android 8.1 后 startForeground 失败

将我的手机升级到8.1DeveloperPreview后,我的后台服务无法正常启动。在我长期运行的服务中,我实现了一个startForeground方法来启动在创建时调用的持续通知。@TargetApi(Build.VERSION_CODES.O)privatefunstartForeground(){//Safecall,handledbycompatlib.valnotificationBuilder=NotificationCompat.Builder(this,DEFAULT_CHANNEL_ID)valnotification=notificationBuilder.setO

android - Context.startForegroundService() 没有调用 Service.startForeground()

我在AndroidO操作系统上使用Service类。我打算在后台使用Service。Androiddocumentation声明IfyourapptargetsAPIlevel26orhigher,thesystemimposesrestrictionsonusingorcreatingbackgroundservicesunlesstheappitselfisintheforeground.Ifanappneedstocreateaforegroundservice,theappshouldcallstartForegroundService().如果使用startForegroun

android - Context.startForegroundService() 没有调用 Service.startForeground()

我在AndroidO操作系统上使用Service类。我打算在后台使用Service。Androiddocumentation声明IfyourapptargetsAPIlevel26orhigher,thesystemimposesrestrictionsonusingorcreatingbackgroundservicesunlesstheappitselfisintheforeground.Ifanappneedstocreateaforegroundservice,theappshouldcallstartForegroundService().如果使用startForegroun