1

MobMy BrodcastReceiver's OnReceive, it works great only when the app is running in the background, I get the notification no problem, but as soon as the user closes the app and waits for the date he specified to be reminded it crashes, is it because the app isn't running? So I'm guessing it's because my app isn't running so the intents can't be retrieved? That's the reason why it crashes?

How I set my alarms, pretty basic stuff;

   public void setAlarm(View view) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, yearDate);
    cal.set(Calendar.MONTH, monthDate);
    cal.set(Calendar.DAY_OF_MONTH, dayDate);
    long alertTime = cal.getTimeInMillis();

    Intent alertIntent = new Intent(this, AlertReceiver.class);
    // store id
    alertIntent.putExtra("id", mainId);
    alertIntent.putExtra("name", name);
    alertIntent.putExtra("releaseDate", releaseDate);

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, mainId, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent);

}

My BrodcastReceiver's OnReceive

  public void onReceive(Context context, Intent intent) {

    int id = intent.getIntExtra("id", -1);
    String name = intent.getStringExtra("name");
    String releaseDate = intent.getStringExtra("releaseDate");

    createNotification(context, "Movie Reminder", name + ": " + releaseDate, "Movie Reminder", id);
}

Maybe I could check if my app isn't running in the onReceive() and if not it opens the app?

1 Answers1

0

There are many issues that might be wrong, without a Logcat, we cant be sure, but here are some of the most likely problems:

getStringExtra("something");

is returning a null string, check documentation here

context has no createNotification method, either create a static one and use your own, or check here how to create a notification or here for a step-by-step guide

Community
  • 1
  • 1
Bonatti
  • 2,778
  • 5
  • 23
  • 42