Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LINE TECHPULSE 2020 - Android Message Capturing

LINE TECHPULSE 2020 - Android Message Capturing

Android Message Capturing by Jerry Che @ LINE TECHPULSE 2020 https://techpulse.line.me/

2102a6b8760bd6f57f672805723dd83a?s=128

line_developers_tw
PRO

December 18, 2020
Tweet

Transcript

  1. Android Message Capturing Jerry / Android Dev

  2. Agenda › What’s Message Capturing? › How Does it Work?

  3. What’s Message Capturing? Demo

  4. What’s Message Capturing? Demo

  5. How Does it Work? Behind The Scenes Step 1 Prepare

    views Step 3 Repeat step 1 & 2 Step 2 Convert views to bitmaps
  6. Step 1 - Prepare Views Step 1 Prepare views Step

    3 Repeat step 1 & 2 Step 2 Convert views to bitmaps › Go through view drawing process › Don’t display views › Call View.measure() and View.layout() ourselves › Display views › Let system do the work Behind The Scenes
  7. Step 1 - Prepare Views Don’t Display Views private fun

    prepareView(parentView: View, adapterPosition: Int) { // Create view val view = listView.adapter.getView(adapterPosition, null, null) // Measure and layout view val specWidth = View.MeasureSpec.makeMeasureSpec(parentView.width, View.MeasureSpec.EXACTLY) val specHeight = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) view.measure(specWidth, specHeight) view.layout(0, 0, view.measuredWidth, view.measuredHeight) }
  8. Step 1 - Prepare Views Display Views private fun displayView(adapterPosition:

    Int) { listView.setSelection(adapterPosition) }
  9. Step 2 - Convert Views to Bitmaps Step 2 Convert

    views to bitmaps Step 3 Repeat step 1 & 2 Step 2 Convert views to bitmaps › Memory usage › Saving and recycling Behind The Scenes
  10. Step 2 - Convert Views to Bitmaps Memory Usage height

    * width * 4 bytes (ARGB_8888: 4 bytes/ pixel) bitmap memory storage Android 3.0 ~ 7.1: in Java heap Android 8: in native heap
  11. Step 2 - Convert Views to Bitmaps Saving and Recycling

  12. Step 2 - Convert Views to Bitmaps Saving and Recycling

    1st message view
  13. Step 2 - Convert Views to Bitmaps Saving and Recycling

    1st bitmap
  14. Step 2 - Convert Views to Bitmaps Saving and Recycling

    1st bitmap 2nd bitmap
  15. Step 2 - Convert Views to Bitmaps Saving and Recycling

    1st bitmap 3rd bitmap 2nd bitmap
  16. Step 2 - Convert Views to Bitmaps Saving and Recycling

    1st bitmap page height limit 3rd bitmap 2nd bitmap
  17. Step 2 - Convert Views to Bitmaps Saving and Recycling

    long bitmap
  18. Step 2 - Convert Views to Bitmaps Saving and Recycling

    long bitmap stored on disk and recycled 1st bitmap
  19. Step 3 - Repeat Step 1 & 2 Step 3

    Repeat step 1 & 2 Step 3 Repeat step 1 & 2 Step 2 Convert views to bitmaps › Message Pagination › Save memory › Avoid exception or crashing Behind The Scenes
  20. › One page at a time › Pages have overlapping

    messages › Auto preloading before end of page
  21. › One page at a time › Pages have overlapping

    messages › Auto preloading before end of page Page 1 Of Messages
  22. › One page has 15 messages › Pages have overlapping

    messages › Auto preloading before end of page Page 1 Of Messages
  23. › One page has 15 messages › Pages have overlapping

    messages › Auto preloading before end of page Page 1 Of Messages Page 2 Of Messages
  24. › One page has 15 messages › Pages have 8

    overlapping messages › Auto preloading before end of page Page 1 Of Messages Page 2 Of Messages
  25. › One page has 15 messages › Pages have 8

    overlapping messages › Auto preloading before end of page Page 1 Of Messages Page 2 Of Messages › Auto pre-load next page › Auto pre-load next page
  26. › One page has 15 messages › Pages have 8

    overlapping messages › Auto preloading is 3rd-to-last message Page 1 Of Messages Page 2 Of Messages › Auto pre-load next page › Auto pre-load next page
  27. listView.setSelection(adapterPos) › Auto pre-load next page › Auto pre-load next

    page
  28. listView.setSelection(adapterPos) › Auto pre-load next page › Auto pre-load next

    page
  29. listView.setSelection(adapterPos) › Load next page preemptively › Re-calculate adapter position

    › Auto pre-load next page › Auto pre-load next page
  30. Step 1 Prepare views Convert views to bitmaps Step 3

    Step 2 Repeat step 1 & 2 › View drawing process › Memory usage › Saving and recycling › Message pagination
  31. Thank you