我正在通过服务类中的alarmreceiver传递未决的意图。但是,在未决的Intent触发之后,广播接收器类未接收到intent.putExtra()信息。这是我触发未决意图的代码
Intent aint = new Intent(getApplicationContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), id, aint, PendingIntent.FLAG_UPDATE_CURRENT);
aint.putExtra("msg", msg);
aint.putExtra("phone", phone);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
警报接收器类别如下
public String msg, phonen;
@Override
public void onReceive(Context context, Intent intent){
Bundle extras = intent.getExtras();
msg = extras.getString("msg");
phonen = extras.getString("phone");
Log.d("onReceive", "About to execute MyTask");
Toast.makeText(context,msg, Toast.LENGTH_LONG).show();
}
没有显示从待处理的意图中接收的Toast中的味精信息。而是显示了空白的吐司。
试试这个
Intent aint = new Intent(getApplicationContext(), AlarmReceiver.class);
aint.putExtra("msg", msg);
aint.putExtra("phone", phone);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
getApplicationContext(),
id,
aint,
// as stated in the comments, this flag is important!
PendingIntent.FLAG_UPDATE_CURRENT);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句