Search code examples
androidandroid-activitynotificationsmessageobserver-pattern

Android: how to send notifications to many activities


Inside my Application class, I have a long-running function (e.g. downloading new data). Once the operation finishes, I want to inform several related activities to refresh their UI. What is the best way to achieve this in Android (the equivalent of postNotification in iOS)?

public class MyApplication extends Application{
    public void onCreate() {
        downloadDataInBackground(); // call operationDone when finished
    }

    private void operationDone(){
        sendMessageToAllRelatedActivities();
    }
}

Solution

  • You can use: Broadcast Receivers for this. Please see following link:

    http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html