Reputation: 69
I am sending a booking id with the intent, then the page with detail information should refresh with the data related to that booking id. The problem is that if the user is at the detail page and she gets a notification, the data is not refreshed.
The problem is happening when I add launch mode as SINGLETASK. This is the intent code:
Intent intent = new Intent(getApplicationContext(), MyJobsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("idIs", bookingId);
intent.setAction(bookingId);
pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
I've tried with a couple of different Intent's flags, but it didn't work either:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
and
PendingIntent.FLAG_CANCEL_CURRENT
Upvotes: 2
Views: 260
Reputation: 153
Update your flag with
notificationIntent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
This flag brings the activity to the front and call onResume
method so you can refresh your data in it after clicking on notification.
Upvotes: 2
Reputation: 544
If you are already in the same activity which you wanted to re-lunch on notification receivedd, then you need to override onNewIntent
on MyJobsActivity
class.
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
//collect your data passed through intent
}
If you are already in the desired activity and re-lunching the same activity, you have to re-lunch the activity with Intent flag as FLAG_ACTIVITY_SINGLE_TOP
. In this case instead of creating new instance of activity it will call onNewIntent
where you can get your latest data passed through intent.
Hope this will help.
Upvotes: 0
Reputation: 4039
Please override onNewIntent()
method in your MyJobsActivity
class. and do collect the intent data as below:
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
// you can collect the intent data from this intent and
// refresh your MyJobsActivity.
}
onNewIntent()
is called for activities that set launchMode to "singleTop" in their package, or if a client used the Intent#FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent)
. In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it.
Please read the documentation for more info on this.
Upvotes: 1