To regularly remind the user that something has to be done, I use a timer to periodically refresh a Notification with a new message. This process must only stop when the user clicks on the Notification, which causes the corresponding Activity to be launched with an Intent containing a flag specifying that the Activity is started by a Notification. In the onResume function of my main Activity, I retrieve this flag and check it. If it is set, I do what is necessary to stop the periodic reminder.
I obtain this behaviour if my application is not active when the user clicks on the Notification, but if the Activity is already launched, the periodic reminder continues again and again. I specify that my Activity is launched in singleInstance mode.
How can I do to receive and treat the Intent sent by the Notification in my already active Activity?
Thanks in advance for the time you will spend trying to help me.
When you are using
singleInstancemode.You would need to overrideonNewIntent(Intent)to receive new Intents for the Activity and do your work thereAlso, you may want to call
setIntent(intent)in onNewIntent to make sure future calls togetIntent()within the Activity lifecycle get the most recent Intent data.