android service notify activity completed best way?

后端 未结 3 1351
悲哀的现实
悲哀的现实 2020-12-30 10:49

I created a service which syncs data from the web on a background thread and want to notify a list activity when the service has completed so it can update it\'s cursor? Wh

3条回答
  •  死守一世寂寞
    2020-12-30 11:24

    As per The Busy Coder's Guide to Advanced Android Development

    An Event Bus is a great way for the service to let other pieces of the app know that certain work was done. It provides a standard communications channel (or “bus”) that event producers and event consumers can hook into. Event producers merely need to hand the event to the bus; the bus will handle directing those events to relevant consumers. This reduces the coupling between the producers and consumers, sometimes even reducing the amount of code needed to source and sink these events.

提交回复
热议问题