I'm trying to pass data to BroadcastReceiver thru PendingIntent of AlarmManager
In the example I'm trying to pass a String and a Parcelable Object, however when I try to read them in the BroadcastReceiver I get null
Activity
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent i = new Intent (this, ReminderBroadcast.class);
i.putExtra("ROUTINE", r);
i.putExtra("MESSAGE", "Example string");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,1234,i,PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pendingIntent);
BroadcastReceiver
public class ReminderBroadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i(LOG_TAG,"notification code is "+ getResultCode());
Log.i(LOG_TAG, "message is: "+ intent.getStringExtra("MESSAGE"));
Log.i(LOG_TAG, "routine " + ((Routine)(intent.getParcelableExtra("ROUTINE"))).getRoutineName());
}
}
Manifest
<activity android:name=".SetupNotificationActivity" />
<receiver android:name=".support.ReminderBroadcast"
android:enabled="true" />
This is driving me crazy, as all the solution found on the inte.net suggest to put PendingIntent.FLAG_UPDATE_CURRENT to solve the issue, but that seems not to work.
Any suggestion? Thanks
To anyone who may incur in the same problem, I found the solution.
The issue was caused by a problem in the Parcelization of the item, which was however not creating any Exception.
So removed that everything worked fine
Thanks for the support
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.