android - AlarmManager with Inner Class BroadcastReceiver -


i new android. playing alarmmanager , had successufully go piece of code running broadcastreceiver separate class.

i trying put broadcastreceiver inner class have no luck on firing broadcastreceiver. had no idea might have gone wrong after hours looking @ code...

here code:

public class innerservice extends service{      @override     public ibinder onbind(intent intent) {         // todo auto-generated method stub         return null;     }      public void oncreate() {         super.oncreate();         intentfilter filter = new intentfilter(innerbroadcastreceiver.class.tostring());         log.d("innerservice","innerservice starts!");         log.d("innerservice","class : "+innerbroadcastreceiver.class.tostring());         this.registerreceiver(new innerbroadcastreceiver(), filter);         scheduletestalarmreceiver(this);      }      public static void scheduletestalarmreceiver(context context) {         log.d("scheduletestalarmreceiver", "scheduletestalarmreceiver start");         intent receiverintent = new intent(context, innerbroadcastreceiver.class);         receiverintent.setaction("com.example.alarmmanagertest.innerservice$innerbroadcastreceiver");         pendingintent sender = pendingintent.getbroadcast(context, 123456789,                 receiverintent, 0);          alarmmanager alarmmanager = (alarmmanager) context                 .getsystemservice(context.alarm_service);         alarmmanager.setrepeating(alarmmanager.elapsed_realtime_wakeup,                 systemclock.elapsedrealtime(), 1000, sender);         log.d("scheduletestalarmreceiver", "scheduletestalarmreceiver complete");     }      private class innerbroadcastreceiver extends broadcastreceiver {          @override         public void onreceive(context context, intent intent) {             // todo auto-generated method stub             log.d("innerbroadcastreceiver","innerbroadcastreceiver alarm manager fires success!");         }      }  } 

it looks alarmmanager tried fire broadcastreceiver every second failed

logcat:

v/alarmmanager(2439): waitforalarm result :4 v/alarmmanager(2439): trigger elapsed_realtime_wakeup or rtc_wakeup 

update

i have tried change code creating intent in oncreate() , scheduletestalarmreceiver() intent = new intent("action_string") , works. seems intent.setaction() not working.

what pros , cons creating intent , without context (intent(context packagecontext, class<?> cls) , intent(string action))? still know why above code failed. can explain?


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -