我有两个应用程序,App A 和 App B。
App A 需要向 App B 发送一些数据(或进行通信以做某事)。
最好的方法是什么。
App B 可以有一个广播监听器来接收来自 App A 的广播。
或者我可以从应用程序 A 导出服务,以便应用程序 B 可以调用 startService()
根据我的经验,广播接收速度非常慢,但调用 startService 时应用程序 A 启动速度很快。
应用 A 是否需要关注 startService() 的任何问题以及来自 Android O 的所有后台服务限制。
最佳答案
Is there is any issues with startService() that App A need to be concerned about with all the background service limitations from Android O.
应用程序 A 应该提供一个导出的 Service
,其他组件可以绑定(bind)到该服务。然后,如果应用程序 B 在前台并已启动 Service
作为 bound Service ,Service
(以及所有 App A)也将被视为在前台。
另请参阅 Background Execution Limits 中的“后台服务限制”段落对于奥利奥(应用程序 B 将是“另一个前台应用程序”)
关于android - 应用程序之间的通信,startService() 或 sendBroadcast(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52042502/