سلام اگه طبق کلیدی که در همین موضوع داده شده پیش رفته باشید میتونید از این کد استفاده کنید :
موفق باشید
کد پیاچپی:
SharedPreferences shared = getSharedPreferences("Prefs", MODE_PRIVATE);
final SharedPreferences.Editor editor = shared.edit();
boolean boolean_from_sp = shared.getBoolean("myBooleanName", true);
if (boolean_from_sp){
mNotificationManager.notify(0, mBuilder.build());
}else{
mNotificationManager.cancel(0);
}
swch.setChecked(boolean_from_sp);
swch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
mNotificationManager.notify(0, mBuilder.build());
else
mNotificationManager.cancel(0);
editor.putBoolean("myBooleanName", isChecked);
editor.apply();
}
});
موفق باشید