//发送广播给服务
Intent intent = new Intent();
intent.setAction("com.study.mobilesafe.unlock");
intent.putExtra("packageName", packageName);
sendBroadcast(intent);
private WatchDogReceiver dogReceiver;
// 注册自定义广播
dogReceiver = new WatchDogReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("com.study.mobilesafe.unlock");
registerReceiver(dogReceiver, filter);
private class WatchDogReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//你的逻辑
}
}
@Override
public void onDestroy() {
super.onDestroy();
flag = true;
if (dogReceiver != null) {
unregisterReceiver(dogReceiver);
dogReceiver = null;
}
}
服务中的自定义广播
最新推荐文章于 2019-08-28 21:46:29 发布