I'm making an app to remind the user of something. I want to show a notification at some time in the future. I've written the code below, following some tutorials, but it doesn't seem to work. At the time I expect the notification, it doesn't show up.
I'm using a BroadcastReceiver and the AlarmManager to make a notification at the desired time. Here's my (simplified) code.
Code to set the time:
try {
        Date date = format.parse(timeInput);//This part works
        long time = date.getTime();//Get the time in milliseconds
        Intent i = new Intent(getBaseContext(), AlarmReceiver.class);
        PendingIntent alarmSender = PendingIntent.getBroadcast(getBaseContext(), 0, i, 0);
        AlarmManager am = (AlarmManager) getBaseContext().getSystemService(Context.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, time, alarmSender);
        Toast.makeText(getBaseContext(), "Keep the app running to receive a reminder notification", Toast.LENGTH_LONG).show();
        super.onBackPressed();
    }catch(Exception e){
        Toast.makeText(getBaseContext(), "Parsing error. Format:\ndd/MM/yyyy and HH:mm", Toast.LENGTH_SHORT).show();
    }
The AlarmReceiver.onReceive() method:
@Override
public void onReceive(Context context, Intent intent) {
    Intent i = new Intent(context, MenuActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, 0);
    NotificationCompat.Builder nBulder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.notify_icon)
            .setContentTitle("title")
            .setContentText("text")
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setContentIntent(pendingIntent)
            .setAutoCancel(true);
    NotificationManagerCompat nManager = NotificationManagerCompat.from(context);
    nManager.notify(0, nBulder.build());
}
Everything is properly declared in the manifest file.