seeing many questions about this but im unable to fix this.
I have this code
public class myBroadcastReceiver extends BroadcastReceiver {
private final String TAG = "myBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Consts.ANDROID_INTENT_ACTION_BOOT_COMPLEATE)){
Intent newinIntent = new Intent(context, ServiceBootCompleated.class);
context.startService(newinIntent);
}
}
}
It starts a Service
and i can debug it using this line
android.os.Debug.waitForDebugger();
I see that return START_NOT_STICKY;
is executed but still
the service is visible as a "running" service in the
Setttings>programs>Running Services
the onDestroy()
is never called unless i stop it manually.
What do i have to do to stop it,
remove it from "Setttings>programs>Running Services " window?
on completion of task, you have to do context.stopService() for stopping this type of unbound service.
Regards,
SSuman185
Once you have completed the work you wanted to do in the background call
stopSelf()
Be sure that any real work you do in the Service is done as a background thread and not in onCreate or onStartCommand.
See http://developer.android.com/reference/android/app/Service.html#ServiceLifecycle for more details on the Service Lifecycle.
Example: