broadcastreceiver - Android: AlarmManager called my Broadcast Receiver even though the trigger time not reached yet -
i having trouble alarm manager , broadcast. code schedule task in hour.
var preference = preferencemanager.getdefaultsharedpreferences (application.context); var alarmmanager = (alarmmanager)application.context.getsystemservice (application.alarmservice); var intent = new intent (application.context, typeof(scheduleusagelogreceiver)); var schedule = new logschedule (1); var serializer = new datacontractjsonserializer (typeof(logschedule)); if (preference.contains (scheduleusagelogreceiver.share_preference_usage_name)) return; using (memorystream ms = new memorystream()) { serializer.writeobject(ms, schedule); var json = encoding.default.getstring(ms.toarray()); var editor = preference.edit (); editor.putstring (scheduleusagelogreceiver.share_preference_usage_name, json); editor.commit (); } var pendingintent = pendingintent.getbroadcast (application.context, 0, intent, 0); alarmmanager.set (alarmtype.rtc, schedule.numbermillisecondtolog, pendingintent);
the broadcast receiver receiving schedule is
[broadcastreceiver] [intentfilter (new string[] { android.content.intent.actionshutdown, "com.htc.intent.action.quickboot_poweroff", android.content.intent.actionbootcompleted } )] public class scheduleusagelogreceiver : broadcastreceiver { public const string share_preference_usage_name = "scheduleusagelogreceiver"; public override void onreceive (context context, intent intent) { toast.maketext (context, "received intent!", toastlength.short).show ();}}
i have bootcomplete action , shutdown action breakpoint intent didn't contain these action don't think problem.
i have checked trigger time 3600000 don't know why trigger when compiled , run application.
if creating pendingintent of alarm past time fired immediately. check , confirm time providing not passed/current time.
Comments
Post a Comment