特殊的广播接收者(界面注册)
更新:HHH   时间:2023-1-7


像锁屏、解锁这种频繁生成事件的广播接收者

注册广播接收者不是在配置文件中   

而是在界面添加代码:  

    IntentFilter filter = new IntentFilter();

filter.addAction("android.intent.action.SCREEN_ON");

filter.addAction("android.intent.action.SCREEN_OFF");

ScreenReceiver receiver = new ScreenReceiver();//广播

this.registerReceiver(receiver,filter);


并且在onDestroy中解绑

unregisterReceiver(receiver);

receiver = null;


返回开发技术教程...