Search code examples
androidandroid-emulatorbroadcastreceiver

AlarmManager setRepeating task failing with error


I am scheduling a repeating task using the AlarmManager and the following code. The task appears to schedule correctly because I get an error when the millis are hit.

Intent i = new Intent(currentContext, AlarmReceiver.class);
i.putExtra("scheduled_alarm", a);
PendingIntent mAlarmSender = PendingIntent.getBroadcast(currentContext, 0, i, 0);   
AlarmManager am = (AlarmManager) currentContext.getSystemService(Context.ALARM_SERVICE);

am.setRepeating(AlarmManager.RTC_WAKEUP, calculateMillis(a, Calendar.MONDAY),
weeklyInterval,mAlarmSender)

The error that appears in my LogCat at the time of the scheduled task is here;

com.example:remote   Trace    error opening trace file: No such file or directory (2)

I have been searching for ages to find a reason for this but cannot. I am using the emulator only because I currently lack a physical device to test it on. My BoradcastReceiver class is here. Any help would be greatly appreciated!

public class AlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
      Alarm a = (Alarm) intent.getExtras().getSerializable("scheduledalarm");   
            Intent creatNewPage = new Intent(context, DisplayAlarm.class);
      creatNewPage.putExtra("alarm", a);
      context.startActivity(creatNewPage);
        } catch (Exception e) {
        }
    }
}

Solution

  • The issue was that I was missing this line;

    createNewPage.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);