Skip to content Skip to sidebar Skip to footer

Does Calling Stopservice() Stops All Awaiting Service Intent

In my application, I'm starting a Service multiple times even when it's running. Its a service that is perpetually running. My question here is, when I call stopService(), will it

Solution 1:

I dont stop my Service, it is STICKYService. When starting app i am controlling the service is running or not like :

publicstaticbooleanisMyServiceRunning(Class<?> serviceClass,Context mContext) {
    ActivityManagermanager= (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            returntrue;
        }
    }
    returnfalse;
}

Usage :

if(!isMyServiceRunning(MyService.class, getApplicationContext())){
       startService(newIntent(this, MyService.class));
}

But when i logout my user i am stopping service like :

Intent serviceIntent=newIntent(mContext,MyService.class);
mContext.getApplicationContext().stopService(serviceIntent);

Post a Comment for "Does Calling Stopservice() Stops All Awaiting Service Intent"