티스토리 뷰

Android/Intent

Intent extras size limit

parkho79 2019. 3. 20. 09:23
300x250
300x250



Intent 관련 글을 쓰다 흥미로운 blog 가 있어 소개한다.

 

Blog | The Intent extras size limit

내용을 보면 intent 로 전달하는 extra size 의 한계에 관한 것으로 아래와 같이 요약할 수 있다.



Size limit?

아래와 같이 Intent 에 대량의 data 를 전달하도록 하면 app 이 crash 될 것이다.

Intent intent = new Intent(this, ActivityB.class);
intent.putExtra("bytes", new byte[1000 * 1000]);
startActivity(intent);

 

Android 6 (API 23) 에서는 exception 발생 시 상세 정보를 알려준다.

android.os.TransactionTooLargeException: data parcel size 1002388 bytes

 

Android 6 이하 버전에서는 각기 다른 exception 이 발생한다.

java.lang.SecurityException: Unable to find app for caller... when publishing content providers
java.io.IOException: Address already in use

 

Testing

정확한 size 한계를 측정하기 위해 실험한 결과는 아래와 같다.

(단, intent 자체의 overhead 도 고려해야 되기 때문에 하단의 값이 실제 순수 data size 라고 할 순 없다.)

        • API 23: 517716 bytes (520107 bytes incl. overhead);
        • API 22: 517876 bytes;
        • API 19: 518368 bytes;
        • API 16: 518396 bytes;
        • API 10: 518580 bytes;

 

Conclusion

Intent 사용 시 가급적 기본적인 정보만을 arguments 로 사용하고 더 많은 data 를 intent 에 담아야 한다면 아래와 같은 옵션으로 대체할 것을 권장한다.

◼ Data 를 file(임시) 로 저장하고 URI 를 활용한자. (Data 가 큰 용량일 경우 유일한 해결책일 것이다.)

◼ Data 를 Application instance 에 저장하자.

◼ Data 를 singleton 에 저장하자.



728x90

'Android > Intent' 카테고리의 다른 글

Intent 이미지 이동  (0) 2019.03.20
Intent (4) - Pending(보류) intent  (0) 2019.02.19
Intent (3) - Implicit(암시적) intent  (0) 2019.02.19
Intent (2) - Explicit(명시적) intent  (2) 2019.02.19
Intent (1)  (0) 2019.02.18
댓글