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 singleInstance
mode.You would need to override onNewIntent(Intent)
to receive new Intents for the Activity and do your work there
Also, you may want to call setIntent(intent)
in onNewIntent to make sure future calls to getIntent()
within the Activity lifecycle get the most recent Intent data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.