W mainactivity mam:
//checkbox for notifications
checkNotification = (CheckBox) popupView.findViewById(R.id.checkNotif);
checkNotification.setChecked(getFromSP("checkbox1"));
checkNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checkNotification.isChecked()) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
prefs.edit().putBoolean("checkeddd",true).apply();
} else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
prefs.edit().putBoolean("checkeddd",false).apply();
}
}
});
public class BootComplete extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
Intent serviceIntent = new Intent(context, NotifService.class);
context.startService(serviceIntent);
}
}
}
i w notifservice:
//checkbox state
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean checked = prefs.getBoolean("checkeddd", false);
if (checked){
Log.d("TAG", "zaznaczony");
notificationManager.notify(NOTIF_ID, builder.build());
}
else{
Log.d("TAG", "odznaczony");
}
Status zapamiętuje, bo jak dałem ten warunek do innej aktywności to w logu idealnie pamiętało i pokazywało stan, ale jak przewaliłem do service to jeżeli wyłączę checkbox (już po zbootowaniu) to apka nadal katuje powiadomieniami, natomiast jeżeli wyłączę i dam restart to nie ma powiadomień, analogicznie z włączaniem dopiero po restacie załapuje.
Tu pytanie: czemu nie zwraca uwagi na stan checkboxa kiedy system pracuje?