我无法通过 checkboxpreferences 停止我的服务。这是 CheckBoxPreference 代码
CheckBoxPreference checkBoxPref = (CheckBoxPreference) getPreferenceManager().findPreference("firstDependent");
checkBoxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue.toString().equals("true")) {
editor.putBoolean("notification_a", true);
editor.commit();
//sendSimpleNotification();
startService(new Intent(settings.this,service.class));
Log.d("Check", "startService from checkbox");
}
else if (newValue.toString().equals("false")){
editor.putBoolean("notification_a", false);
editor.commit();
//mNotificationManager.cancel(SIMPLE_NOTIFICATION_ID);
stopService(new Intent(getApplicationContext(),service.class));
Log.d("Check", "stopService from checkbox");
}
return true;
}
});
因此,如果未选中该复选框,服务将停止但没有任何反应。为什么?