I'm trying to use user-preferences checkbox to show or not to show the notification on the status bar. So far I have done this :
MainActivity.java
@Override
public void UserPref {
String notificationTitle = "ASD";
String notificationMessage = "ASD ASD ASD";
Intent targetIntent = new Intent(this, MainActivity.class);
int requestCode = AppSingleton.NOTIFICATION_ID;
PendingIntent contentIntent = PendingIntent.getActivity(this,
requestCode, targetIntent, 0);
String statusBarTickerText = "ASD ASD ASD";
int icon = R.drawable.ic_launcher;
Notification notification = new Notification(icon, statusBarTickerText,
System.currentTimeMillis());
notification.flags = Notification.FLAG_ONGOING_EVENT
| Notification.FLAG_NO_CLEAR;
notification.setLatestEventInfo(this, notificationTitle,
notificationMessage, contentIntent);
nm.notify(AppSingleton.NOTIFICATION_ID, notification);
}
I'm able to show the notification all the time. But now I want to add User-Preferences through which the user can disable or enable the notification. Here is my code for PreferenceActivity :
UserPreference.java
public class UserPreference extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
final CheckBoxPreference checkboxPref = (CheckBoxPreference) getPreferenceManager()
.findPreference("Checkbox");
checkboxPref
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference,
Object newValue) {
Log.d("MyApp", "Pref " + preference.getKey() + " changed to " + newValue.toString());
return true;
}
});
}
}
I'm not able to call the function when the CheckBox is checked from the MainActivity.java but my I'm able to print boolean value in DDMS.
Please see and correct me what I'm doing wrong and help me to overcome this problem.