android - Service updating an activity that is not active -
what best way accomplish this?
1) mainactivity (i.e. ui) created , starts service starts listening tcp socket (should intentservice, since mainactivity client?).
2) service receives messagges , updates ui when comes (using localbroadcastmanager?).
3) user closes activity clicking or home button. mainactivity not active anymore, service should keep running in background, receiving messages , somehow communicating mainactivity (which not there). have no idea this, runonuithread()?
4) when user comes , resumes mainactivity, ui should not show new messages, "old" ones: every message has received since service started.
5) messages not permanent: should deleted if entire app killed, phone turned off ecc. have same life-cycle of service.
my fear there's no such thing communicating activity not active (point 3) , should write messages in local file, checking updates oncreate() , onresume(). there smarter way? points 3 , 4 critical ones. best way accomplish them? (no need write code, explain using keywords or link examples).
the mainactivity not active anymore
the mainactivity
may destroyed, more merely "not active".
and somehow communicating mainactivity
even if there instance of mainactivity
not yet garbage-collected, if destroyed, never used again. , cannot talk mainactivity
instance not yet exist.
when user comes , resumes mainactivity, ui should not show new messages, "old" ones: every message has received since service started.
mainactivity
needs pull data in case, rather having data pushed it. whether pull asking service data (via bindservice()
, via posting gimmemydata
event on event bus, etc.), or whether activity , service working through intermediary (e.g., contentprovider
), you.
Comments
Post a Comment