android app to the challenge
DESCRIPTION
Writing an Android app is easy, but making it "smooth" is not always simple. The UX demands and over 1000 different Android devices present a big challenge for any new and existing app. Learn some methods to optimize your app an make it up to the challengeTRANSCRIPT
![Page 1: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/1.jpg)
AndroidApp to the challenge
Udi Cohen
![Page 2: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/2.jpg)
We'll talk about..● Graphics:
– Over Draw
– Detect UI glitches
– Optimizing layouts with HierarchyViewer
● Profiling with Traceview● Helping the GC with HPROF● Playing tough with StrictMode● Getting intimate with the OS using EventLog● Hardware Accelerate your app● Tips
![Page 3: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/3.jpg)
whoami
![Page 4: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/4.jpg)
Over Draw● Draw something on top of
something else● Rule – aim overdraw to 2x● Could indicate a complex
hierarchy● “Show GPU overdraws” on
Developer options (4.2+)
4x
3x
2x
1x
![Page 5: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/5.jpg)
Over Draw – Solutions
● Remove default background● getWindow().setBackgroundDrawable(null)
● <item name="android:windowBackground">@null</item>
● Transparent regions in 9patches
● Use tools● Tracer for OpenGL
● Hierarchy Viewer
![Page 6: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/6.jpg)
Over DrawHappens to the best of us
![Page 7: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/7.jpg)
Tracer for OpenGL
● Layout tree step by step● See redundant draw operations● Heavy
![Page 8: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/8.jpg)
Dumpsys gfxinfo
● Since Jelly Bean● Last 128 frames● Frame < 16ms● 3 columns
– Draw
– Process
– Execute
●
113
2537
4961
7385
975
9 1721 29
33 4145 53
57 6569 77
81 8993 101
105109
113117
121125
0
1
2
3
4
5
6
7
8
9
Execute
Process
Draw
![Page 9: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/9.jpg)
Hierarchy Viewer
![Page 10: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/10.jpg)
Traceview Profiling
● Performance of each method● Graphical interface● Run from DDMS or code
![Page 11: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/11.jpg)
Traceview Profiling
![Page 12: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/12.jpg)
Traceview Profiling
Inclusive: Includes child functions
Exclusive: This function only
![Page 13: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/13.jpg)
Traceview Profiling
![Page 14: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/14.jpg)
Traceview Profiling
So...what's the problem here?
![Page 15: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/15.jpg)
Helping out the GC
● Allocation Tracker (DDMS)●
![Page 16: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/16.jpg)
Helping out the GC
● Memory profiling → Dalvik HPROF file
Use code or DDMS ● Use hprof-conv to convert to standard● Use any Java HPROF analyzer
![Page 17: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/17.jpg)
Helping out the GC
● Eclipse MAT (Memory Analyzer Tool)
![Page 18: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/18.jpg)
Helping out the GC
● Histogram & Dominator tree
![Page 19: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/19.jpg)
Tips - Bitmaps
● InJustDecodeBounds – Load only properties
● InBitmap – reuse other allocation● InSampleSize – good for preview● Resource folders
![Page 20: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/20.jpg)
StrictMode
● Problems Detector● Single thread or the entire VM● Show dialog, write to Log and more..● Usually used to detect slow operations on
UI thread● Came with Gingerbread (2.3)
![Page 21: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/21.jpg)
Log
● EventLog– Adb logcat -b events
– Framework level logs
– DB and system operations
![Page 22: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/22.jpg)
Hardware Acceleration
● android:hardwareAccelerated="true"ortargetApi >= 14
● Efficient drawing model● Compatibility issues
– Custom views
– Unsupported operations
![Page 23: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/23.jpg)
Hardware Acceleration
● Good for animations● View Layers
![Page 24: Android app to the challenge](https://reader033.vdocument.in/reader033/viewer/2022042613/5472cd92b4af9fbe0a8b517a/html5/thumbnails/24.jpg)
Tips● Always Measure● Lint
– Comes with the SDK
– Scan the project's for optimizations
– Great Eclipse/IntelliJ integration
● ListView – Easy on the getView()● Alpha – Watch it...● Storage Read/Write● Direct access inside the class (!Get/Set)● SQLite indexes