简体   繁体   English

Android:如果系统在前台运行,系统会停止未绑定的服务吗?

[英]Android: will system stop unbound service if it's running in foreground?

The application uses bound service. 该应用程序使用绑定服务。 So, the service is NOT started using startService anywhere. 因此,该服务不会在任何地方使用startService启动。 Every activity which needs to access the service binds to it using bindService. 需要访问服务的每个活动都使用bindService绑定到该活动。

In some situations service is going foreground (with startForeground). 在某些情况下,服务会成为前台(使用startForeground)。

In particular there might be a situation when nothing is bound to service (which, according to the doc means that service will be stopped) but it's running in the foreground (which means that it wont' be stopped). 特别是可能存在一种情况,即没有任何东西绑定到服务(根据文档,这意味着该服务将被停止),但它在前台运行(这意味着它不会被停止)。 Which of those rules have priority? 哪些规则具有优先权? Will system stop unbound service when it's running in foreground? 在前台运行时,系统会停止未绑定的服务吗?

Thanks. 谢谢。

In some situations service is going foreground (with startForeground). 在某些情况下,服务会成为前台(使用startForeground)。

This is not particularly useful, as the process will already be in the foreground, because the activity using the service is in the foreground. 这不是特别有用,因为该过程已经在前台,因为使用该服务的活动在前台。

Which of those rules have priority? 哪些规则具有优先权?

The service will be destroyed after the last client has unbound from it. 最后一个客户端解除绑定后,该服务将被销毁。 startForeground() does not impact this. startForeground()不会对此产生影响。

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

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