I am using Otto to send events from IntentService to my Activity. IntentService is Downloading files from server and send progress to Activity this is working with otto very well.
-
I have done so far
registered otto in
OnResumeBusStation.getBus().unregister(this);created function to receive events
@Subscribe
public void receiveProgress(Message message){
Log.i("Downloader",message.getMessage()+"");
}
unregister bus in
OnPauseBusStation.getBus().unregister(this);I have
Buttonon which click DownloadService is started and this service sends download progress toreceiveProgressfunction.
but when I close my app and Restart app and then if DownloadSerice still downloading file it never send Download progress event on receiveProgress
so how to relink this.
I assume that
BusStation.getBus()returns a singleton. However, when you restart the app the singleton has to be created again and therefore it is not the same instance anymore.You can solve this problem by using LocalBroadcastManager instead:
https://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html