In my project I am using a service that returns START_STICKY
in the onStartCommand function.
I use the service to run some background processing in an asynctask (which I call from the onStartCommand function).
I need to kill the service, because it keeps running when I check the app settings on my phone.And set the AlarmManager to call the service again after X hours.
I have tried
if (isMyServiceRunning()) {
stopService(new Intent(context, MFilterIt.class));
}
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager
.getRunningServices(Integer.MAX_VALUE)) {
if ("com.sixdee.mfilterit.MFilterIt".equals(service.service
.getClassName())) {
return true;
}
}
return false;
}
I call this in my asynctask.so I see this behaviour.if the delay that I set in AlarmManager is 2.The delay becomes 6 (2*3).I see this behaviour only when I killing the service in the above mentioned fashion
Is there any other way or am I doing any wrong.