Note that there are some explanatory texts on larger screens.

plurals
  1. POBroadcast receiver throws error after reboot when application was not opened before
    text
    copied!<p>I have a broadcast receiver, launching after reboot to set several alarms with the help of the alarm manager. The broadcast and the receiving after the reboot works perfectly, however the alarm being set in this broadcast throws an error when being fired.</p> <pre><code>E/AndroidRuntime(4330): at mobileTechnology.geoCalendar.SetAlarm.checkReminder(SetAlarm.java:82) E/AndroidRuntime(4330): at mobileTechnology.geoCalendar.SetAlarm.access$1(SetAlarm.java:80) E/AndroidRuntime(4330): at mobileTechnology.geoCalendar.SetAlarm$1.gotLocation(SetAlarm.java:73) E/AndroidRuntime(4330): at mobileTechnology.geoCalendar.CurrentLocation$2.onLocationChanged(CurrentLocation.java:70) </code></pre> <p>When I open the application after the reboot before the other alarms are fired, there will be no error. Do you have any idea, why the app is behaving that way? In the broadcast receiver I'm accessing a normal java class (no activity) to determine the current position by a callback. Is there a problem accessing this class when the application was not opened before?</p> <p><strong>EDIT:</strong> I guess I configured my manifest file the wrong way, as there is missing an Intent filter. Can anyone tell me what's the right way to do it?</p> <pre><code>&lt;receiver android:name="SetAlarm"&gt;&lt;/receiver&gt; </code></pre> <p><strong>EDIT2:</strong></p> <p>thank you, so here is some more code of my project:</p> <p>During runtime a set up several alarms for events by using the alarm manager. The alarm is created by calling</p> <pre><code>new SetAlarm (Context context, Bundle bundle, Long time_how_far_in_advance_alarm_should_be_fired) </code></pre> <p>The bundle contains detailed information about the event (name, time ...) and the SetAlarm constuctor looks like the following:</p> <pre><code>AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, SetAlarm.class); intent.putExtra("data", bundle); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, bundle.getInt("id"), intent,PendingIntent.FLAG_UPDATE_CURRENT); Calendar cal = Calendar.getInstance(); *&lt;set time for reminder&gt;* alarmMgr.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent); </code></pre> <p>The receiver is in the same class as the broadcast and defined by</p> <pre><code>&lt;receiver android:name="SetAlarm"&gt;&lt;/receiver&gt; </code></pre> <p>Until this point everything works perfect as alarms are being fired when they should be and a notification will be displayed.</p> <p>To reload the alarms after a reboot, there is another class ReloadAlarms, loading all Events out of a database and setting up the alarms again.</p> <pre><code>public void onReceive(Context context, Intent intent) &lt;receiver android:name="ReloadAlarms" &gt; &lt;intent-filter &gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>The alarms are set up again by calling SetAlarm and passing the context, just received from the first on receive method. SetAlarm(Context context, Bundle bundle, long reminder)</p> <p>As soon as the onReceive method in SetAlarm is called, it validates if the alarm has to be set to another time. If yes I call new SetAlarm(_context, newBundle, newTime); _context is again the context I just received from the onReceive method.</p> <p>The problem is that the onReceive method is called continously. (at least in case a reschedule of the event is necessary, even without reboot)</p> <p>How does the onReceive method recognize, when an alarm was fired. Is it possible that this happens because I'm passing the context received by the onReceive method to new SetAlarm(...) for the reschedule? </p> <p><strong>END Edit2</strong></p> <p>Thank you for your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload