I'm trying to let the user enable/disable if they want to receive notifications or not. I managed to implement a checkbox for notification and to create a preference class.
This is the my preferences class
import com.pushbots.push.Pushbots;
...
public class UserSettings extends PreferenceActivity {
private CheckBoxPreference notification;
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
SharedPreferences settingsPrefs = PreferenceManager.getDefaultSharedPreferences(this);
notification = (CheckBoxPreference) findPreference("prefSendNotification");
notification.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceChange(Preference preference,
Object newValue) {
if (newValue.toString().equals("true"))
{
notificationsOn();
Pushbots.sharedInstance().setNotificationEnabled(true);
}
else
{
notificationsOff();
Pushbots.sharedInstance().setNotificationEnabled(false);
}
return true;
}
private void notificationsOn() {
Pushbots.sharedInstance().setNotificationEnabled(true);
}
private void notificationsOff() {
Pushbots.sharedInstance().setNotificationEnabled(false);
}
@Override
public boolean onPreferenceClick(Preference preference) {
// TODO Auto-generated method stub
return false;
}
});
}
}
However when I uncheck the checkbox I still receive the notification. Whats the problem?