我正在尝试使用以下方法从其他活动取消注册我的服务,但它没有做任何事情。
这是我的代码:
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateUI(intent);
}
};
public void resetnetmon(View view) { // reset NetworkStats
unregisterReceiver(broadcastReceiver);
stopService(intent);
finish();
}
我的服务的类名是 BroadcastService.java
答案 0 :(得分:1)
代码停止/启动服务:
stopService(new Intent(this, BroadcastService.class));
startService(new Intent(this, BroadcastService.class));
答案 1 :(得分:0)
对于有活动的停止服务:
this.stopService(new Intent(this, YourServiceName.class));
如果您想了解更多详情,请参阅此问题want to run and stop service with activity android