I need to change a variable only when a user clicks on a notification. I tried to use SharedPreferences in the activity after the notification redirects to it and then retake this variable next time I need it, but I don't know why it doesn't work.
Does anyone know where exactly does the onClick of the Notification is triggered ?
My notification is defined as follows:
protected Notification createNotification() {
CharSequence title = "New notification";
CharSequence content = "";
Notification notification = new Notification(R.drawable.app_icon,
title, System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
PendingIntent contentIntent = createPendingIntent();
notification.setLatestEventInfo(this, title, content, contentIntent);
return notification;
}
protected PendingIntent createPendingIntent() {
Intent intent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
return contentIntent;
}
protected void showNotification() {
try {
mNM.notify(NOTIFICATION_ID, createNotification());
} catch (Exception e) {
}
}
Thank you.