Note that there are some explanatory texts on larger screens.

plurals
  1. POBroadcastReceiver is not called
    text
    copied!<p>I have to following code to call the BroadcastReceiver:</p> <pre><code> public class WorkItemAlarmManager { ... public void initAlarm(HelpMe helpMe, String delay,String period,WorkItem workItem){ //HelpMe = Activity helpMe.registerReceiver(new WorkItemAlarmHandler() , new IntentFilter("WORK_ITEM_ALARM")); Intent intent = new Intent("WORK_ITEM_ALARM"); intent.setClass(helpMe, WorkItemAlarmManager.class); intent.putExtra("work_item", workItem); PendingIntent mAlarmSender = PendingIntent.getService(helpMe, 0,intent, 0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); //System.out.println("START"+System.currentTimeMillis()); calendar.add(Calendar.SECOND, calcDelayMillis(delay)); //System.out.println("END"+calendar.getTimeInMillis()); AlarmManager am = (AlarmManager) helpMe.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), mAlarmSender); } ... } </code></pre> <p>and the BroadcastReceiver:</p> <pre><code>public class WorkItemAlarmHandler extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { .... } } </code></pre> <p>But the WorkItemAlarmHandler is never called.</p> <p>Update: I tried to register the BroadcastReceiver in the manifest at first. But that didn't work:</p> <pre><code>&lt;receiver android:name="de.helpme.alarm.WorkItemAlarmHandler" android:enabled="true" android:label="WorkItemAlarmHandler" &gt; &lt;intent-filter&gt; &lt;action android:name="WORK_ITEM_ALARM" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>Thanks for your answers :). Now it works - but i dont yet know which one is the correct because i implemented both answers at once. If a figure out which was the right one i mark the right as answer.</p> <p><strong>Update:</strong> The cause of the problem as i see it was:</p> <pre><code>PendingIntent mAlarmSender = PendingIntent.getService(helpMe, 0,intent, 0); </code></pre> <p>With this code it works fine:</p> <pre><code>PendingIntent mAlarmSender = PendingIntent.getBroadcast(helpMe, 0, intent, 0); </code></pre> <p>Thanks again for all 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