请问有没有人知道Android 7.0(牛轧糖)在处理意图附加项方面与Android 6.0(棒棒糖)相比是否有任何更改?
简而言之:我的应用程序在4.1(16)到6.0(23)的所有版本上都按预期工作,但在Android 7.0(24)上崩溃了!
该应用程序创建一个带有意图的待处理意图,该意图指向一个具有额外信息的自定义广播接收器。然而,在Android 7上,广播接收器接收到的意图中没有任何额外信息。
MainActivity.java
Intent intent = new Intent(context, PollServerReceiver.class);
// TODO: Remove after DEBUGGING is completed!
intent.putExtra("TESTING1", "testing1");
intent.putExtra("TESTING2", "testing2");
intent.putExtra("TESTING3", "testing3");
// PendingIntent to be triggered when the alarm goes off.
final PendingIntent pIntent = PendingIntent.getBroadcast(context,
PollServerReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Setup alarm to schedule our service runs.
AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstRun, freqMilis, pIntent);
PollServerReceiver.java
Bundle extras = intent.getExtras();
Log.d(TAG, "onReceive: TESTING1 = " + extras.getString("TESTING1")); // null here
// None of the three "TESTING*" keys are there!
for (String key : extras.keySet()) {
Object value = extras.get(key);
Log.d(TAG, String.format("onReceive extra keys: %s %s (%s)", key, value.toString(), value.getClass().getName()));
}
堆栈跟踪明显表明空指针异常是崩溃的原因。如果在所有版本中都崩溃,那么这并不奇怪,但在这种情况下,只有最新的Android才会崩溃。请问是否有任何想法?
注意:我尝试使用不同的标志创建挂起意图,包括(0
,PendingIntent.FLAG_UPDATE_CURRENT
,PendingIntent.FLAG_CANCEL_CURRENT
),仍然得到完全相同的结果。