[英]Android: how to send notifications to many activities
Inside my Application class, I have a long-running function (eg downloading new data). 在我的Application类内部,我有一个长期运行的功能(例如,下载新数据)。 Once the operation finishes, I want to inform several related activities to refresh their UI.
操作完成后,我想通知几个相关活动以刷新其UI。 What is the best way to achieve this in Android (the equivalent of postNotification in iOS)?
在Android(相当于iOS中的postNotification)中实现此目标的最佳方法是什么?
public class MyApplication extends Application{
public void onCreate() {
downloadDataInBackground(); // call operationDone when finished
}
private void operationDone(){
sendMessageToAllRelatedActivities();
}
}
You can use: Broadcast Receivers for this. 您可以使用:广播接收器。 Please see following link:
请查看以下链接:
http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.