简体   繁体   中英

intent.getExtra returns null while passing data from activity to BroadcastReceiver

    Intent intent=new Intent(this, AlarmReceiver.class);
    intent.putExtra("Test","Test Intent");
    PendingIntent pendingIntent=PendingIntent.getBroadcast(this,0,intent,0);
    alarmManager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis()+2000,pendingIntent);

In BroadcastReceiver onReceive()

   String test=intent.getStringExtra("Test");

Intent.getExtra returns null while passing data from activity to BroadcastReceiver? Please help

这是正确的方法-指定一个标志!

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM