android - AlarmManager fires twice -



android - AlarmManager fires twice -

i trying utilize androids alarmmanager. problem is, fires twice right after 1 another.

public class schedulesomething { public static void schedule(pojo pojo) throws jsonprocessingexception { final objectmapper mapper = new objectmapper(); final string pojoasjson = mapper.writevalueasstring(pojo); final intent alarmintent = new intent(myapplication.getappcontext(), pojoalarmreceiver.class); alarmintent.putextra(pojo_as_json, pojoasjson); final pendingintent pi = pendingintent.getbroadcast(myapplication.getappcontext(), 0, alarmintent, pendingintent.flag_one_shot); am.set(alarmmanager.rtc_wakeup, system.currenttimemillis() + pojo.getscheduledtime() + 10l, pi); } } public class alarmreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { // stuff. onreceive() beingness called twice, every time. } }

ofcourse have checked if phone call schedule(pojo pojo) method twice sadly, that's not it. right now, work around sooner or later, i'd resolve in clean way. best regards , knows what's going wrong.

ok, sure there more elegant ways solve problem have found working sollution. problem right after broadcastreceiver intercepted alarm, made phone call 1 time again intercepted bc (eventhough particular bc doesn't filter new_outgoing_call nor phone_state...). did adding string , check within alarmreceiver:

public class schedulesomething { public static final string source = "source"; public static void schedule(pojo pojo) throws jsonprocessingexception { final objectmapper mapper = new objectmapper(); final string pojoasjson = mapper.writevalueasstring(pojo); final intent alarmintent = new intent(myapplication.getappcontext(), pojoalarmreceiver.class); alarmintent.putextra(pojo_as_json, pojoasjson); alarmintent.putextra(source, "com.mypackage.alarm"); final pendingintent pi = pendingintent.getbroadcast(myapplication.getappcontext(), 0, alarmintent, pendingintent.flag_one_shot); am.set(alarmmanager.rtc_wakeup, system.currenttimemillis() + pojo.getscheduledtime() + 10l, pi); } } public class alarmreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { final string source = intent.getstringextra(registrationcalllogic.source); if ((source == null) || !source.equals("com.mypackage.alarm")) { return; } // stuff. onreceive() beingness called twice, every time. } }

android

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -