本文介绍了从活动到的BroadcastReceiver Android的传球数据显示空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有它使用一个AlarmManager调用一个BroadcastReceiver在特定时间点的活动。这一切工作正常,只是当我尝试一些额外的字符串调用的BroadcastReceiver时,增加的意图,他们总是拿出另一端为空。
I've got an activity which uses an AlarmManager to call a BroadcastReceiver at a particular point in time. This all works fine, except when I try to add some extra strings to the intent when calling the BroadcastReceiver, they always come up as null on the other end.
活动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
BroadcastReceiver code
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "TestString: " + intent.getStringExtra("testString"));
}
的TestString的内容总是空
中的BroadcastReceiver,我究竟做错了什么?
The content of 'teststring' is always null
in the BroadcastReceiver, what am I doing wrong?
推荐答案
试着用得到它:
intent.getExtras().get("testString");
这篇关于从活动到的BroadcastReceiver Android的传球数据显示空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!