intent.putExtra()在挂起的意图中不起作用 [英] intent.putExtra() in pending intent not working

查看:232
本文介绍了intent.putExtra()在挂起的意图中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从服务类中通过alarmreceiver传递未决的意图.但是,在未决的Intent触发之后,广播接收器类未接收到intent.putExtra()信息.这是我触发未完成的意图的代码

I am passing a pending intent through alarmreceiver, from a service class. But, after the pendingIntent fires, the intent.putExtra() information is not being received by the broadcastreceiver class. Here is my code for firing the 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);

警报接收器类别低于

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();
}

从待定意图中接收到的味精信息未显示.而是显示了空白的吐司.

The msg information in toast, that is being received from pending intent, is not being shown. Instead, a blank toast is shown.

推荐答案

尝试一下

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);

这篇关于intent.putExtra()在挂起的意图中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆