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 question sharedpreferences 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

android , restful services

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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -