I am currently using this code, to start the service and stop it, but the service is never stopped. What is wrong?
final Switch enableSwitch = (Switch) findViewById(R.id.isEnabledSwitch);
enableSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
startService(new Intent(getBaseContext(), la_svc.class));
}
else {
stopService(new Intent(getBaseContext(), la_svc.class));
stopService(new Intent(getBaseContext(), lb_svc.class));
}
}
});
disableservice.java
What have I done wrong? How can I stop a service, when the switch is unchecked?