发送群众演员的BroadcastReceiver群众演员、BroadcastReceiver

由网友(人已逝丶物已非)分享简介:我有运行以下code(时间和间隔的定义)的活动:I have an Activity that runs the following code (time and interval are defined):Intent buzzIntent = new Intent(getBaseContext(), BuzzR...

我有运行以下code(时间和间隔的定义)的活动:

I have an Activity that runs the following code (time and interval are defined):

Intent buzzIntent = new Intent(getBaseContext(), BuzzReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, buzzIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
buzzIntent.putExtra("interval", interval);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, interval * 60 * 1000, pendingIntent);

和一个BroadcastReceiver具有以下的onReceive:

and a BroadcastReceiver that has the following onReceive:

@Override
public void onReceive(Context context, Intent intent) {
    try {
        int interval = intent.getIntExtra("interval", -1);
        <... more code ...>
    } catch (Exception e) {
        e.printStackTrace();
    }
}

但intent.getIntExtra()返回-1(这是不是间隔在活动的价值,我查了),所以由于某种原因的BroadcastReceiver没有得到,我存入的意图群众演员活动。

but the intent.getIntExtra() returns -1 (which isn't the value of interval in the Activity, I checked), so for some reason the BroadcastReceiver isn't getting the extras that I store into the intent in the Activity.

我已经试过了大量的不同的东西,但似乎没有任何工作。我失去了一些东西呢?

I've tried a ton of different things but nothing seems to work. Am I missing something here?

推荐答案

设置标记 FILL_IN_DATA ,同时创造挂起的意图如下:

Set flag FILL_IN_DATA while creating pending intent as below:

PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, buzzIntent, Intent.FILL_IN_DATA);

您应该这样改变之后接收广播接收机演员。

You should receive extras in broadcast receiver after this change.

阅读全文

相关推荐

最新文章