Search code examples
androidbroadcastreceiveralarm

Receiver doesn´t react on Alarm in Android


... and i still have no Idea whats wrong. Hopefully someone can help me, i´m not reallyexperienced in Android.

This is my Alarm Service, defined in Reporter.java:

    alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(getBaseContext(), Reporter.MyReceiver.class);
PendingIntent  pendingAlarmIntent = PendingIntent.getBroadcast(getBaseContext(), 0, alarmIntent, 0);
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1*1000, 1*30*1000,  pendingAlarmIntent);

This is my receiving inner Class:

    public class MyReceiver extends BroadcastReceiver{

public MyReceiver(){
    super();
}

public void onReceive(Context context, Intent intent) {
    Log.e("log_cat","Alarm empfangen");
    new GetControls();
}

}

And this is what i added to the Manifest:

         <receiver android:name="de.sonderfarben.tmc_reporter3.Reporter$MyReceiver" android:process=":remote"/>

thanx!!


Solution

  • That is because you have specified a time in the past. If you are trying to have your event occur one second from now, with an ELAPSED_REALTIME_WAKEUP alarm, use SystemClock.elapsedRealtime()+1000, not 1*1000.


    UPDATE

    Also, you cannot use a regular inner class. You can use a static inner class, or a separate public class. Regular inner classes can only be instantiated by an instance of the outer class; Android does not have one of those to use.