私のコードでは、次のように条件付きでサービスを開始します。
Intent intent = new Intent(context, MyService.class);
context.startService(intent);
2回サービスを開始しないように、以前に同じサービスを開始したことがあるかどうかを確認できるかどうか教えてください。
ありがとうございました。
私のコードでは、次のように条件付きでサービスを開始します。
Intent intent = new Intent(context, MyService.class);
context.startService(intent);
2回サービスを開始しないように、以前に同じサービスを開始したことがあるかどうかを確認できるかどうか教えてください。
ありがとうございました。
Check this:
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.example.MyService".equals(service.service.getClassName())) {
return true;
}
}
return false;}
@bigstones: I don't know how, but I have a service that it can be created how many times as you like (maybe because I create inside it various runnable objects).