Android app to the challenge

25
Android App to the challenge Udi Cohen

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 challenge

Transcript of Android app to the challenge

Page 1: Android   app to the challenge

AndroidApp to the challenge

Udi Cohen

Page 2: Android   app to the challenge

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

whoami

Page 4: Android   app to the challenge

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

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

Over DrawHappens to the best of us

Page 7: Android   app to the challenge

Tracer for OpenGL

● Layout tree step by step● See redundant draw operations● Heavy

Page 8: Android   app to the challenge

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

Hierarchy Viewer

Page 10: Android   app to the challenge

Traceview Profiling

● Performance of each method● Graphical interface● Run from DDMS or code

Page 11: Android   app to the challenge

Traceview Profiling

Page 12: Android   app to the challenge

Traceview Profiling

Inclusive: Includes child functions

Exclusive: This function only

Page 13: Android   app to the challenge

Traceview Profiling

Page 14: Android   app to the challenge

Traceview Profiling

So...what's the problem here?

Page 15: Android   app to the challenge

Helping out the GC

● Allocation Tracker (DDMS)●

Page 16: Android   app to the challenge

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

Helping out the GC

● Eclipse MAT (Memory Analyzer Tool)

Page 18: Android   app to the challenge

Helping out the GC

● Histogram & Dominator tree

Page 19: Android   app to the challenge

Tips - Bitmaps

● InJustDecodeBounds – Load only properties

● InBitmap – reuse other allocation● InSampleSize – good for preview● Resource folders

Page 20: Android   app to the challenge

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

Log

● EventLog– Adb logcat -b events

– Framework level logs

– DB and system operations

Page 22: Android   app to the challenge

Hardware Acceleration

● android:hardwareAccelerated="true"ortargetApi >= 14

● Efficient drawing model● Compatibility issues

– Custom views

– Unsupported operations

Page 23: Android   app to the challenge

Hardware Acceleration

● Good for animations● View Layers

Page 24: Android   app to the challenge

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

Page 25: Android   app to the challenge

Thank you

@udinic

http://www.udinic.com

[email protected]