public class RegisterService extends Service {
private ScreenOnOFFReceiver receiver;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
//1.创建广播接收者对象
receiver = new ScreenOnOFFReceiver();
//2.创建意图过滤器对象
IntentFilter filter = new IntentFilter();
//指定接收什么广播
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
//3.注册广播接收者
registerReceiver(receiver, filter);
}
@Override
public void onDestroy() {
super.onDestroy();
//反注册广播接收者
unregisterReceiver(receiver);
}
}