안드로이드 7.0 (누드)이 안드로이드 6.0 (롤리팝)에 비해 인텐 트 엑스트라를 처리하는 방법에 변화가 있다면 아는 사람 있습니까?안드로이드 7 의도 불필요한 엑스트라
짧은 이야기 : 내 앱이 4.1 (16)에서 6.0 (23)의 모든 버전에서 작동하지만 Android 7.0 (24)에서 충돌합니다!
앱에서 추가 기능이있는 맞춤형 브로드 캐스트 수신기에 의도가있는 보류중인 인 텐트를 만듭니다. 그러나 안드로이드 7에서는 방송 수신자가받은 의도에 추가 정보가 없습니다. 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()));
}
스택 추적
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);
MainActivity.java
분명히 충돌의 원인으로 NullPointerException이 있습니다. 모든 버전에서 충돌이 발생하는 것은 그리 이상한 일은 아니지만이 경우에는 최신 Android 만 사용할 수 있습니다. 누구든지 아이디어가 있으십니까?
참고 : (0
, PendingIntent.FLAG_UPDATE_CURRENT
, PendingIntent.FLAG_CANCEL_CURRENT
)을 포함한 다른 플래그로 보류중인 인 텐트를 만들려고했지만 여전히 동일한 결과가 나타납니다.
질문에서 코드를 사용하여 문제를 재현 할 수 없으므로 실제 코드가 질문의 코드와 일치하지 않을 수도 있습니다. 실제 코드에서, 커스텀'Parcelable' 클래스 형태의 추가 기능이 있습니까? – CommonsWare
네, 3 개의 String String 엑스트라 외에 Parcelable 객체를 같은 의도로 저장하고 있습니다. 물론 Receiver에서 수신 된 의도와 Tree String Extras에도 빠져 있습니다. – Konaras
24는 Parcelable 객체를 AlarmManager에 전달하는 것을 허용하지 않습니다. http://stackoverflow.com/questions/38466080/dp5-7-0-does-adding-extras-to-a-pending-intent-fail –