欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Anroid接收熄屏广播消息 Android内存泄漏熄屏广播 

程序员文章站 2022-05-16 13:25:56
...
BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if(Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
                
            }
        }
};

//动态注册
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(mReceiver, filter);

//记得在合适的时机比如Activity的onDestroy方法里反注册释放掉资源以免内存泄漏
unregisterReceiver(mReceiver);