有誰知道是否有任何與Android 6.0(棒棒糖)相比Android 7.0(Nougat)處理意圖演員的更改嗎?Android 7意向演員失蹤
長話短說:我的應用程序在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()));
}
堆棧跟蹤顯然給出了NullPointerException異常是飛機失事的原因。 如果它會在所有版本中崩潰,那麼它不會太奇怪,但在這種情況下,它只有最新的android。有沒有人有任何想法?
注意:我試圖創建包含不同標誌的待定意圖,包括(0
,PendingIntent.FLAG_UPDATE_CURRENT
,PendingIntent.FLAG_CANCEL_CURRENT
)仍然得到完全相同的結果。
我不能用你的問題代碼重現你的問題,所以我猜測可能是真正的代碼不符合問題的代碼。在你真實的代碼中,是否有你自定義的'Parcelable'類的形式? – CommonsWare
是的,除了三個測試字符串額外功能外,我還在同一個意圖中存儲了一個Parcelable對象。當然,它也從接收者收到的意圖以及樹字符串額外缺失。 – Konaras
24不允許傳入一個Parcelable對象到AlarmManager中,http://stackoverflow.com/questions/38466080/dp5-7-0-does-adding-extras-to-a-pending-intent-fail –