I am creating an Intent and adding a string extra to it, then I create a PendingIntent, which is given to the alarm manager to execute:
String value = "someValue";
Intent intent = new Intent(this, FetchService.class);
intent.putExtra(AppConstants.KEY, value);
alarmIntent = PendingIntent.getService(this, 0, intent, 0);
Up until this point, everything is fine, and I checked with a debugger that the extra was actually set. Next, when the onHandleIntent(intent) is called inside my service, the extra doesn't seem to exist anymore
@Override
protected void onHandleIntent(Intent intent) {
// App crashes here
String value = intent.getStringExtra(AppConstants.KEY);
...
}
I can't seem to figure out why the extra is not there. Have I missed something?
Thanks.
Was missing the PendingIntent.FLAG_UPDATE_CURRENT when creating my PendingIntent as Karakuri pointed out.