Teo Inke
Teo Inke

Reputation: 5986

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

I have an app with two processes - the MainActivity and a background Service. I need the same information in both, and this info comes from my server (a JSON response). I was loading this JSON from both processes, but as this JSON may get bigger it's pretty inefficient to load twice.

What is the safest or best practice to share this info?

Any other suggestion/recommendation is very appreciated.

Thanks in advance!

Upvotes: 1

Views: 169

Answers (1)

Saeed Masoumi
Saeed Masoumi

Reputation: 8916

Most common way is sending a broadcast and also you should avoid using singletons, for more information see this link

Android and RESTful services

It's better to take a look at Event Bus

As the doc says :

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

Upvotes: 1

Related Questions