@TryLoveCatch
2022-04-22T12:42:09.000000Z
字数 1721
阅读 490
Android知识体系
<receiver android:name="com.clericyi.basehelper.network.NetworkReceiver">
<intent-filter>
<action android:name="android.intent.action.BATTERY_LOW"/>
</intent-filter>
</receiver>
// 注册
networkReceiver = new NetworkReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
registerReceiver(networkReceiver, intentFilter);
// 注销(如果没有注销,将会发生内存泄漏)
unregisterReceiver(networkReceiver);
正常发送广播
//注册
networkReceiver = new NetworkReceiver();
localBroadcastManager = LocalBroadcastManager.getInstance(this); // --> 以单例模式进行创建
localBroadcastManager.registerReceiver(networkReceiver, new IntentFilter("需要去过滤的信息"));
// 发送消息
localBroadcastManager.sendBroadcast(Intent);
// 注销
localBroadcastManager.unregisterReceiver(networkReceiver);
https://blog.csdn.net/ly0724ok/article/details/117333915
https://www.jianshu.com/p/48010df647ef
https://juejin.cn/post/6844904163613081614
https://juejin.cn/post/6844903972344446984