I have an activity that uses AlarmManager to call BroadcastReceiver at a specific point in time. All this works fine, except when I try to add some extra lines to the intent when calling BroadcastReceiver, they always appear as null on the other end.
Operation code:
Intent intent = new Intent(this, ScheduleReceiver.class); intent.putExtra("testString", "I'm a string"); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 999, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC, System.currentTimeMillis(), pendingIntent);
BroadcastReceiver Code
public void onReceive(Context context, Intent intent) { Log.v(TAG, "TestString: " + intent.getStringExtra("testString")); }
The content of "teststring" is always null in BroadcastReceiver, what am I doing wrong?
source share