I need to open a same activity from multiple notification trays each notification brings different data to the activity
Tried applying launchMode
as SingleTop
and SingleTask
also tried by setting different ACTIVITY_FLAGS
For example, If server returned 6 notifications to the same activity then if I click on any notification it opens activity with an information which came from very first notification to mobile than all
Piece of Code From Manifest
<activity android:launchMode="singleTop" android:name=".activity.EditAssuranceActivity" />
Piece of code from Notification Receiver Activity (Hitting EditAssuranceActivity)
if (targetActivity.equals("events")) {
intent = new Intent(this, ViewEventActivity.class);
intent.putExtra("page_title", Message);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else if (targetActivity.equals("assurances")) {
intent = new Intent(this, EditAssuranceActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("page_title", Message);
}
else {
intent = new Intent(this, MainActivity.class);
}
intent.putExtra("_id", parameter_id.get("post_id"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
I got a expected solution after setting the value of 'requestCode' which I am passing in PendingIntent.getActivity(this, 0 /* Request code */, intent,PendingIntent.FLAG_ONE_SHOT);
to some random number instead of 0.
Different notifications from server traverse through this same code but each time 'requestCode' will get different random number so after clicking on each notification same activity will open with a value brought by that specific notification.
Previous Code
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,PendingIntent.FLAG_ONE_SHOT);
Modified Code
Random random1 = new Random();
int rand1 = random1.nextInt(1000);
PendingIntent pendingIntent = PendingIntent.getActivity(this, rand1 /* Request code */, intent,PendingIntent.FLAG_ONE_SHOT);