Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart / refresh contents of activity on notification click

I am trying to refresh the contents of an activity on click of a notification. I can navigate to the activity when I am in some other activity and I click on the notification. What I am trying to achieve is, I am in Activity A which is displaying some content. I get a new notification, I click on it Activity A should either be relaunched or the content in the activity should be refreshed with respect to what I am passing in the PendingIntent of the Notification.

What all I have done,

  1. Tried setting PendingIntent.FLAG_CANCEL_CURRENT and PendingIntent.FLAG_UPDATE_CURRENT

  2. Tried setting Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP in the intent I am passing along with the pending intent.

  3. Checked the data in onNewIntent() its doesn't get refreshed. I get the same data which I have passed in the old intent.

  4. Passed a unique requestCode along with the PendingIntent as well, still the same.

Any Other suggestions?

like image 717
iZBasit Avatar asked Sep 26 '14 07:09

iZBasit


People also ask

How to restart an activity in Android?

How to restart an Activity in Android? This example demonstrates how do I restart an Activity in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code ...

What is auto refresh with notifications and how does it work?

Auto Refresh With Notifications will help you automatically refresh on one page until "Excludes" contents are not shown on the page. You will be notified loudly with sounds which are set in...

How to reload activity in Android?

This example demonstrates how to reload activity in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.

What notifications are sent when a device needs to restart?

When a device requires a restart, the client shows a notification to the end user of the upcoming restart. Toast notification A Windows toast notification informs the user that the device needs to restart.


1 Answers

If you use Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP, this should recreate the activity if it was in the stack, or start a new activity if it wasn't in the stack. If you don't want the activity to be recreated (if it is already in the stack), you can use Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP.

like image 70
David Wasser Avatar answered Oct 13 '22 02:10

David Wasser