2017년 4월 27일 목요일

Android N - AlarmManager 사용시 PendingIntent 에 Parcelable 로 전달시 수신부에서 null 이 되는 현상

AlarmManager 사용시 PendingIntent 에 Parcelable 로 전달시 수신부에서 null 이 되는 현상

Android N 이후부터 발생(정확히 7.0 인지 7.1 인지는 모르겠다)

// send
intent.putExtra(EXTRA_DATA, xxx);
// xxx  Parcelable 구현 객체
 
// receive
final XXX xxx = bundle.getParcelable(EXTRA_DATA);
// 여기서 null 발생.

관련하여 검색을 해보면 아래 issue tracker 에도 등록이 되어 있다.

google 에서는 “Won't Fix (Intended behavior)” 로 처리.

app 에서 수정 필요.

// send
Bundle bundle = new Bundle();
bundle.putParcelable(EXTRA_DATA, xxx);
intent.putExtra(EXTRA_DATA, bundle);
 
// receive
Bundle bundle = intent.getBundleExtra(EXTRA_DATA);if (bundle != null) {
    final XXX xxx = bundle.getParcelable(EXTA_DATA);
}


참고로, 문자열이나 정수형 등은 정상적으로 전달이 된다.
only Parcelable 객체만 해당되는 것 같다.

댓글 없음:

댓글 쓰기

Android Jetpack viewpager2

  Android Jetpack ViewPager2 기본 개념 및 샘플 코드 오늘은 안드로이드 개발에 있어서 굉장히 유용한 컴포넌트 중 하나인 ViewPager2에 대해 이야기해볼까 합니다. ViewPager2는 사용자 인터페이스에서 여러 화면을 좌우...