android - Share info between two processes - what's the safest way? -
i have app 2 processes - mainactivity
, background service
. need same information in both, , info comes server (a json response). loading json both processes, json may bigger it's pretty inefficient load twice.
what safest or best practice share info?
- broadcast , copy json
mainactivity
service
- assume safe practice , broadcast won't lost - use
sharedpreferences
store locally , both consume "local" json until app closed. according this questionsharedpreferences
works fine between processes.
any other suggestion/recommendation appreciated.
thanks in advance!
most common way sending broadcast , should avoid using singletons, more information see link
it's better take @ event bus
as doc says :
simplifies communication between components
- decouples event senders , receivers
- performs activities, fragments, , background threads
- avoids complex , error-prone dependencies , life cycle issues
Comments
Post a Comment