Make a warning Software Note

Source: Internet
Author: User

Supplement the last problem http://blog.csdn.net/fancylovejava/article/details/9862183

An Android software with a calendar reminder

Setting an alert clock for each record is of course sending a broadcast to a broadcast receiver, but the problem arises,

I am saving a notebook, and then when I add the alarm time settings for this notebook, I will judge whether it is the latest time or not. If it is true, I will send a broadcast,

This broadcast is sent using pendingintent. getbroadcast (this method already contains the sendbroadcast method ),

When an alert is triggered after a broadcast is received in the broadcast receiver, I use the default alert policy of the mobile phone system,

Uri mediauri = ringtonemanager. getdefaulturi (ringtonemanager. type_ringtone );
Mmediaplayer = mediaplayer. Create (context, mediauri );

Mmediaplayer. setlooping (true );

Get the default ringtone, and then start and stop control ....

Then, when the alarm rings, start an activity in the broadcast receiver. Set this activity to I. addflags (intent. flag_activity_new_task );

Otherwise, there will be an error message. Android errors are very user-friendly. I will solve this problem according to the error message.

After the activity is started, send the broadcast to the broadcast receiver in the activiyt,

Intent I = new intent ("test. notepadalarmreceiver ");
Bundle bundle = new bundle ();
Bundle. putparcelable ("testnote", note2 );
I. putextra ("testnotealarm", bundle );

Pendingintent Pi = pendingintent. getbroadcast (alarmshowactivity. This, 0, I, 0 );

Alarmmanager alarm = (alarmmanager) getsystemservice (alarm_service );
Alarm. Set (alarmmanager. rtc_wakeup, system. currenttimemillis () + d1-d2, Pi );

Some code is pasted out,

However, the problem arises again, that is, the bundle object passed in cannot be automatically updated, and the serialized objects in the bundle Object received in the broadcast receiver are always the beginning.

Pendingintent. getbroadcast (alarmshowactivity. This, 0, I, 0,

Google, found an article http://blog.csdn.net/dadoneo/article/details/8164058

The bundle data cleanup is similar to my situation,

intent.setFlags(PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

He provided this line of code, which means pendingintent updates the current one and only launches oneshot once,

Then I pasted it in my project and ran it. The result returned an error,

Java. Lang. illegalargumentexception: Can't use flag_receiver_boot_upgrade here is another user-friendly error prompt. Google error prompt

Bytes

PendingIntent p=PendingIntent.getBroadcast(context, id, i,PendingIntent.FLAG_CANCEL_CURRENT);

According to the above modification, I thought it was done, and the result was still an error. I don't understand it ......

The final solution is:

Pendingintent Pi = pendingintent. getbroadcast (alarmshowactivity. This, 0, I, pendingintent. flag_update_current | pendingintent. flag_one_shot );

Instead of setflags in intent, pendingintent. flag_update_current | pendingintent. flag_one_shot

The bundle data objects received in the broadcast receiver are indeed different,

PS: But I still don't understand why I intent. after the bundle object obtained by getextra (), bundle. clear (), intent. removeextra () does not work. I am so angry. Do you understand this?

Please leave a message !!! Thank you.

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.