title: Android: programatically registering Receiver not working
body: <p>i have a BroadcastReceiver which worked fine when i made it a seperate class and registered it in the Manifest. However, i need it as an inner class, because i want to refresh parts of the UI if the app is in the foreground and for that i have to register it programatically (because in order to register it in the Manifest file, it has to be static and therefor cant access non static outer class methods).</p>
  
  <p>I am trying to do it like this, but it just does nothing (i change the hour and minutes for test purposes)</p>
  
  <pre><code>registerReceiver(new DayCheckReceiver(), new IntentFilter());
  
  AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  dayCheckIntent = new Intent(this, DayCheckReceiver.class);
  
  dayCheckAlarmIntent = PendingIntent.getBroadcast(this, 2000000000, dayCheckIntent, 0); // i use this high number because i use 1+ for a growing list
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeInMillis(System.currentTimeMillis());
  calendar.set(Calendar.HOUR_OF_DAY, 14);
  calendar.set(Calendar.MINUTE, 19);
  if (calendar.before(Calendar.getInstance())) {
      calendar.add(Calendar.DATE, 1);
  }
  alarmManager.setExact(AlarmManager.RTC, calendar.getTimeInMillis(), dayCheckAlarmIntent);
  </code></pre>
  
  <p>This is the BroadcastReceiver as an inner Class:</p>
  
  <pre><code>public class DayCheckReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          //load
          SharedPreferences sharedPrefs = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
          Gson gson = new Gson();
          String json = sharedPrefs.getString(TASKLIST_FILE, null);
          Type type = new TypeToken&lt;ArrayList&lt;TaskItem&gt;&gt;() {
          }.getType();
          mTaskList = gson.fromJson(json, type);
  
          //modifications
          if (mTaskList != null &amp;&amp; mTaskList.size() &gt; 0) {
              for (int i = 0; i &lt; mTaskList.size(); i++) {
                  mTaskList.get(i).shiftDayChecks();
                  mTaskList.get(i).resetTimeLeft();
              }
          }
  
          //save
          SharedPreferences.Editor editor = sharedPrefs.edit();
          gson = new Gson();
          json = gson.toJson(mTaskList);
          editor.putString(TASKLIST_FILE, json);
          editor.apply();
  
          tasksFragment.loadTaskList();
          tasksFragment.updateTaskList();
      }
  }
  </code></pre>