Slide 1

Slide 1 text

TransactionTooLargeException Keishin Yokomaku / potatotips #34 @ UIEvolution

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Transaction TooLargeException 3 potatotips #34 @ UIEvolution

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

TransactionTooLargeException Similar exceptions ▸ CursorWindowAllocationException ▸ The app opens too many cursors, or allocate too many data in a cursor. 10 potatotips #34 @ UIEvolution

Slide 11

Slide 11 text

TransactionTooLargeException Keishin Yokomaku / potatotips #34 @ UIEvolution

Slide 12

Slide 12 text

DroidKaigi Call for Speakers will close on November 1st 12