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?
- Broadcast and copy the JSON from
MainActivity
toService
- I assume this is a safe practice and my broadcast won't get lost - Use
SharedPreferences
to store this locally and both consume from this "local" JSON until the app is closed. According to this questionSharedPreferences
works fine between processes.
Any other suggestion/recommendation is very appreciated.
Thanks in advance!
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 :