Android multiple notifycation pass different data to the same actiivity

Source: Internet
Author: User

If you have this requirement, you may find that when you practice, multiple notifycation will pass the same data when clicked.

Normally we might write this.

Notification Notification = new Notification (r.drawable.ic_launcher_9, Name, System.currenttimemillis ());

Intent Intent = new Intent (Mcontext, Themeinfo.class);
Bundle bundle = new bundle ();
Bundle.putstring ("Apkid", PackageName);
Bundle.putboolean ("Isapplied", false);
Intent.putextra ("bundle", bundle);
Intent.addflags (Intent.flag_activity_new_task);

Pendingintent pendingintent = pendingintent.getactivity (mcontext, 0, intent, 0);

Notification.setlatesteventinfo (Mcontext, name, "Hello", pendingintent);
Notification.flags = Notification.flag_auto_cancel;

LOG.D ("Newthemechooser__:themechangereceiver", "Hascode:" + packagename.hashcode () + "installed" + packageName);
Notificationmanager.notify (Packagename.hashcode (), notification);

What's the reason?

The answer is on the Red font section.

Personally, the whole intent will be serialized into memory via parcel after notifycation click.

The data will be overwritten if the 2nd parameter of Pendingintent Requestcode is the same. Results in the same data being passed.

How to solve it?

It's simple, too.

Pendingintent pendingintent = pendingintent.getactivity (Mcontext, Packagename.hashcode (), intent, 0);

In other words, the 2nd parameter must be unique in different notifycation.

The answer is actually what I found on the StackOverflow. StackOverflow is a good place if you have a problem that you want to solve quickly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.