android - Does onReceive get called in BroadcastReceiver for AlarmManager if device is already awake -
i'm having trouble getting broadcastreceiver work. onreceive not getting called. not using service. setting alarm in activity's oncreate method. using rtc_wakeup. if device awake? onreceive called anyway? want onreceiver called if device awake. need have receiver called if device asleep want execute code receiver carries out when activity starts manually. here how starting alarm:
alarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service); intent = new intent(context, servicestarter.class); pendingintent pi = pendingintent.getactivity(context, 0, i, pendingintent.flag_update_current); am.set(alarmmanager.rtc_wakeup, system.currenttimemillis(), pi);
in manifest:
<receiver android:process=":remote" android:name=".servicestarter" android:exported="true"></receiver>
but if device awake? onreceive called anyway?
yes.
here how starting alarm:
you using getactivity()
. component not activity
. broadcastreceiver
. use getbroadcast()
build pendingintent
trigger broadcastreceiver
.
in manifest:
remove android:process="remote"
, not need it, , harms user wasting ram. also, remove android:exported="true"
, not need it, , weakens security allowing trigger broadcastreceiver
.
Comments
Post a Comment