TransactionTooLargeException

 TransactionTooLargeException

Bbe9718bebdafbdc8dabbe3cadf1bc46?s=128

Keishin Yokomaku

October 26, 2016
Tweet

Transcript

  1. TransactionTooLargeException Keishin Yokomaku / potatotips #34 @ UIEvolution

  2. TransactionTooLargeException About Me ▸ Keishin Yokomaku ▸ Drivemode, Inc. /

    Principal Engineer ▸ KeithYokoma: GitHub / Twitter / Qiita / Tumblr / Stack Overflow ▸ Books: Mobile App Dev Guide / Android Academia / Grimoire of Android ▸ Fun: Gymnastics / Cycling / Photography / Motorsport ▸ Today’s Quote: “ΨοΩʔ࠷ߴ” 2 potatotips #34 @ UIEvolution
  3. Transaction TooLargeException 3 potatotips #34 @ UIEvolution

  4. TransactionTooLargeException Inter-Process Communication (IPC) ▸ Mechanisms that OS provides to

    allow processes to share(transfer) data. ▸ Underlying system ▸ Deep Dive into Android IPC/Binder Framework (http://bit.ly/2dsFzaI) ▸ Key classes built upon IPC framework in Android ▸ Parcelables (Intent, Bundle, Bitmap, etc…) and Binder ▸ System Services (PackageManager, ActivityManager, etc…) 4 potatotips #34 @ UIEvolution
  5. TransactionTooLargeException Example of IPC public class MainActivity extends Activity {

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View button = findViewById(R.id.button); button.setOnClickListener(v -> { Intent intent = new Intent(this, ImageViewActivity.class); intent.putExtra(ImageViewActivity.EXTRA_IMAGE, getBitmap()); startActivity(intent); }); } public Bitmap getBitmap() { // returns huge bitmap object } } 5 potatotips #34 @ UIEvolution
  6. TransactionTooLargeException Example of IPC public class MainActivity extends Activity {

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View button = findViewById(R.id.button); button.setOnClickListener(v -> { Intent intent = new Intent(this, ImageViewActivity.class); intent.putExtra(ImageViewActivity.EXTRA_IMAGE, getBitmap()); startActivity(intent); }); } public Bitmap getBitmap() { // returns huge bitmap object } } 6 potatotips #34 @ UIEvolution
  7. TransactionTooLargeException !!! FAILED BINDER TRANSACTION !!! (parcel size = 1048700)

    7 potatotips #34 @ UIEvolution
  8. TransactionTooLargeException !!! FAILED BINDER TRANSACTION !!! (parcel size = 1048700)

    ▸ A process is allowed to use 1Mb memory space (for buffer) for IPC ▸ NEVER transfer a large data (e.g. Bitmap) across processes through IPC. ▸ Otherwise you will see TransactionTooLargeException. ▸ Also be aware NOT to make too many transactions at the same time ▸ When the sum of all individual data exceeds 1Mb, you will see TransactionTooLargeException. 8 potatotips #34 @ UIEvolution
  9. TransactionTooLargeException How to avoid ▸ 3 ways to avoid TransactionTooLargeException

    ▸ Split a huge data into small pieces ▸ e.g. PackageManager defines flags to control data size ▸ Use Uri to share a huge data ▸ cf. Intent#setData() ▸ Cache the data to reduce the number of IPC 9 potatotips #34 @ UIEvolution
  10. TransactionTooLargeException Similar exceptions ▸ CursorWindowAllocationException ▸ The app opens too

    many cursors, or allocate too many data in a cursor. 10 potatotips #34 @ UIEvolution
  11. TransactionTooLargeException Keishin Yokomaku / potatotips #34 @ UIEvolution

  12. DroidKaigi Call for Speakers will close on November 1st 12