gpt4 book ai didi

java - 绑定(bind)服务和前台服务有什么区别?

转载 作者:行者123 更新时间:2023-11-30 00:17:35 25 4
gpt4 key购买 nike

我试图创建一个服务,该服务可以在应用程序打开时与 AppUI 交互,并在应用程序关闭时继续工作。

我听说 bindService() 调用创建了一个可以与应用程序通信的绑定(bind)服务。同时,一些资源说 startService() 可以通过调用 onStartCommand() 中的 startForeground() 进一步成为前台服务> 回调,然后使用它们与 App 通信。

任何人都可以提供实现我的需求的最佳方式以及这之间的区别吗?

最佳答案

来自官方文档:https://developer.android.com/guide/components/services.html

绑定(bind)

A service is bound when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, receive results, and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed.

前景

A foreground service performs some operation that is noticeable to the user. For example, an audio app would use a foreground service to play an audio track. Foreground services must display a status bar icon. Foreground services continue running even when the user isn't interacting with the app.

看起来你应该使用前台服务。

关于java - 绑定(bind)服务和前台服务有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46971093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com