Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android cannot pass intent extras to AlarmManager

I thought this would solve my problem, but it doesn't.

I have this code to send my alarm:

public void triggerAlarm() {
    AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(ALARM_SERVICE);
    alarmManager = (AlarmManager) getContext().getSystemService(ALARM_SERVICE);
    Intent intent = new Intent(getContext(), AlarmReceiver.class);
    intent.putExtra("Id", nextDue.id.get() + "");
    String passed = intent.getStringExtra("Id");
    Log.d("DEBRRUG", "The extra im passing: " + passed);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), i++, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.set(AlarmManager.RTC_WAKEUP, soonest.dueTime.get(), pendingIntent);
}

My DEBRRUG statement indicates that the extra being passed is 8.

This is my alarm receiver:

@Override
    public void onReceive(Context context, Intent intent) {
        String passed = intent.getStringExtra("Id");
        Log.d("DEBRRUG", "The extra im receiving: " + passed);
    }

Here, my DEBRRUG statemnt indicates that the extra im receiving is NULL.

Note: Something that could, possibly, be interesting is that my triggerAlarm method is being called from within my ContentProvider. Don't know if that helps you understand my problem better or not.

like image 533
stackoverflow_sucks Avatar asked Nov 20 '25 00:11

stackoverflow_sucks


1 Answers

Use intent.getExtras().getString("id")

like image 177
chaitanya dalvi Avatar answered Nov 21 '25 15:11

chaitanya dalvi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!