在两个进程之间共享信息——什么是最安全的方式?

Share info between two processes - what's the safest way?

我有一个包含两个进程的应用程序 - MainActivity 和后台 Service。我在两者中都需要相同的信息,并且此信息来自我的服务器(JSON 响应)。 我正在从两个进程加载此 JSON,但由于此 JSON 可能会变大,因此加载两次效率很低。

分享此信息的最安全或最佳做法是什么?

非常感谢任何其他 suggestion/recommendation。

提前致谢!

最常见的方式是发送广播,而且您应该避免使用单例,有关详细信息,请参阅此 link

Android and RESTful services

不如看看Event Bus

正如文档所说:

simplifies the communication between components

  • decouples event senders and receivers
  • performs well with Activities, Fragments, and background threads
  • avoids complex and error-prone dependencies and life cycle issues