我通过alarmreceiver从服务类传递一个待处理的意图.但是,在pendingIntent触发后,broadcastreceiver类没有接收到intent.putExtra()信息.这是我的用于触发pendingIntent的代码
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);
Run Code Online (Sandbox Code Playgroud)
警报接收器类如下
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();
}
Run Code Online (Sandbox Code Playgroud)
未显示正在从待处理意图接收的Toast中的msg信息.而是显示空白吐司.