android - How to communicate with a background activity from intent service -


so have activity holding data mydata. have background intentservice runs periodically , updates data in database reload when background activity comes foreground. want reload when background service ran. used broadcast receivers work if activity in foreground. doesn't receive events if activity in background.

another way thinking write flag "reload" in preferences when intentservice runs , when backgrounded activity resumes checks flag , reloads if necessary , set false again.

can suggest better solution? thanks.

the simple way? use static method, myintentservice.didanythingchange() (making sure clear flag when activity reloads). or maybe sequence number, you'd have if (this.updateno != myintentservice.getlatestupdateno()) in activity.

the complicated way? use dynamically registered broadcastreceiver in activity, , send matching broadcast intentservice. let broadcastreceiver set flag in activity.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -