Anroid接收熄屏广播消息

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);

 

你可能感兴趣的:(android,内存泄漏,广播,熄屏)