一、动态:
https://blog.csdn.net/qq_30098019/article/details/51498766
二、静态广播:
静态广播在service里:
没有static运行时会显示需要一个空参数的构造器?暂时不清楚为啥?
最好不要再用静态广播,如下:
https://www.jianshu.com/p/a68ec364bc6e
注册动态广播接收器
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("user");
registerReceiver(myReceiver, intentFilter);
BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String msg = intent.getStringExtra("info");
Log.i("myReceiver", "get dynamic receiver......data = " + msg);
}
};
发送广播:
Intent intent = new Intent(“user”);
intent.putExtra("info", data);
sendBroadcast(intent);