title: AlarmManager with Inner Class BroadcastReceiver
body: <p>I am new to android. I was playing with the AlarmManager and had successufully go a piece of code running with the BroadcastReceiver as a separate class.</p>
  
  <p>I am now trying to put the BroadcastReceiver as inner class but have no luck on firing the BroadcastReceiver. I had no idea what might have gone wrong after hours looking at the code...</p>
  
  <p>Here is my code:</p>
  
  <pre><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!");
          }
  
      }
  
  }
  </code></pre>
  
  <p>It looks like the AlarmManager tried to fire the BroadcastReceiver every second but failed</p>
  
  <p>Logcat:</p>
  
  <pre><code>V/AlarmManager(2439): waitForAlarm result :4
  V/AlarmManager(2439): trigger ELAPSED_REALTIME_WAKEUP or RTC_WAKEUP
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have tried to change the code for creating intent in <code>onCreate()</code> and <code>scheduleTestAlarmReceiver()</code> to <code>intent = new intent("action_string")</code> and it works. It seems that <code>intent.setAction()</code> is not working.</p>
  
  <p>What will be the pros and cons for creating intent with and without context (<code>Intent(Context packageContext, Class&lt;?&gt; cls)</code> and <code>Intent(String action)</code>)?
  But I would still like to know why the above code failed. Can anyone explain?</p>