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/

LINE Developers Taiwan

December 18, 2020
Tweet

More Decks by LINE Developers Taiwan

Other Decks in Programming

Transcript

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

    views Step 3 Repeat step 1 & 2 Step 2 Convert views to bitmaps
  2. 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
  3. 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) }
  4. 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
  5. 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
  6. Step 2 - Convert Views to Bitmaps Saving and Recycling

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

    long bitmap stored on disk and recycled 1st bitmap
  8. 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
  9. › One page at a time › Pages have overlapping

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

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

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

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

    overlapping messages › Auto preloading before end of page Page 1 Of Messages Page 2 Of Messages
  14. › 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
  15. › 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
  16. 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