SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Samsung Developer Office Hours NYC



     X Means Y:
  Interpreting the
 Development Tools
            Copyright © 2012CommonsWare, LLC
01-03 01:32:11.986: E/AndroidRuntime(17991):
Caused by: android.os.NetworkOnMainThreadException




                  Copyright © 2012CommonsWare, LLC
StrictMode
●   Reports obvious long-running stuff on main
    application thread
●   Network I/O automatically reported on
    Android 3.0+
    –   Do not disable the error – fix the problem!
    –   Opt-in for Android 2.3
         ●   Can also configure to report disk I/O on main
             thread, failure to close files/databases/cursors,
             etc.           Copyright © 2012CommonsWare, LLC
Copyright © 2012CommonsWare, LLC
06-29 23:11:17.796: I/Choreographer(691):
Skipped 18 frames! The application may be doing
too much work on its main thread.




                  Copyright © 2012CommonsWare, LLC
Choreographer
●   Information Message in LogCat
    –   “Skipped N frames” * 16ms = amount of time
        you took on main application thread
    –   The more frames skipped, the more likely it is
        the user will notice
         ●   UI frozen and not responsive
         ●   Animation/scrolling hiccups
    –   Android 4.1+

                          Copyright © 2012CommonsWare, LLC
Project Butter
●   UI Updates @ 60 frames/second
●   Objective: smoother UI updates
    –   Especially animations
●   Transparent to developers
    –   No code changes to “opt into” Butter effects
●   Google I/O 2012: “For Butter or Worse”

                      Copyright © 2012CommonsWare, LLC
Project Butter Ramifications
●   Only ~16ms Per Frame
    –   Your code on the main application thread
    –   Framework code
    –   Other interruptions (e.g., background process)
●   Net: Get Off the Main Application Thread!
    –   Anything taking more than a few milliseconds
        needs to move to background thread or be
        executed incrementally
                      Copyright © 2012CommonsWare, LLC
12-12 08:56:20.746: E/AndroidRuntime(1570):
java.lang.RuntimeException: Can't create handler inside
thread that has not called Looper.prepare()




                    Copyright © 2012CommonsWare, LLC
Looper and Handler
●   Queuing mechanism
●   Used by main application thread
●   Error results from trying to do wrong thing on
    background thread
    –   setContentView()
    –   requestLocationUpdates()
●   HandlerThread
                    Copyright © 2012CommonsWare, LLC
java.lang.StackOverflowError
  at android.widget.TextView.onDraw(TextView.java:4329)
  at android.view.View.draw(View.java:6993)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
  at android.view.View.draw(View.java:6996)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
  at android.view.View.draw(View.java:6996)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
  at android.view.View.draw(View.java:6996)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
  at android.view.View.draw(View.java:6996)
  at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
.
.
.
                      Copyright © 2012CommonsWare, LLC
StackOverflowError
●   Your code?
    –   Too-deep recursion
●   View/ViewGroup code?
    –   Too-complex UI: nested containers
    –   8KB stack space on main application thread




                      Copyright © 2012CommonsWare, LLC
StackOverflowError
●   Diagnostics
    –   Open UI in emulator
         ●   Or device if you embed ViewServer in it
    –   Run Hierarchy View
         ●   Eclipse perspective or via monitor
    –   Count depth
    –   Find stuff safe to eliminate
         ●   Containers with only one child
                           Copyright © 2012CommonsWare, LLC
07-13 10:42:23.820: E/AndroidRuntime(2065):
java.lang.OutOfMemoryError




                Copyright © 2012CommonsWare, LLC
OutOfMemoryError
●   Limited heap sizes
    –   16-64MB, depending on OS version and device
        capabilities
●   Non-compacting garbage collector
    –   Cannot allocate a block big enough for your
        request
●   Primary culprit: bitmaps
    –   1080p image = ~8MB
                      Copyright © 2012CommonsWare, LLC
OutOfMemoryError
●   Diagnostics
    –   MAT
        ●   Dump heap (HPROF) using Debug or DDMS
        ●   Load into MAT (Eclipse plug-in or standalone)
        ●   Hunt for culprits
    –   adb shell dumpsys meminfo
        ●   Lots of low-level information
        ●   Difficult to accurately interpret

                          Copyright © 2012CommonsWare, LLC
OutOfMemoryError
●   BitmapFactory.Options
    –   inSampleSize: downsample for less heap use
    –   inPurgeable/inInputShareable: for sharing
        backing data for mutations of common ancestor
        bitmap
    –   inBitmap: for reusing existing Bitmap buffer
         ●   Must be of the same dimensions and bit depth
         ●   Maintain your own object pools versus
             fragmenting your heap
                          Copyright © 2012CommonsWare, LLC
I/DEBUG   (18110):   *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (18110):   Build fingerprint: 'MOTO_O2DE/umts_sholes/umts_sholes/sholes:2.1-...
I/DEBUG   (18110):   pid: 23912, tid: 23913 >>> com.example.test <<<
I/DEBUG   (18110):   signal 11 (SIGSEGV), fault addr 0000000c
I/DEBUG   (18110):    r0 00140120 r1 00000048 r2 00000000 r3 00140168
I/DEBUG   (18110):    r4 afe3ae08 r5 00000006 r6 00140158 r7 0000a000
I/DEBUG   (18110):    r8 100ffcf8 r9 4185eef8 10 4185eee0 fp 001243b0
I/DEBUG   (18110):    ip 00000000 sp 100ffc50 lr afe0f130 pc afe0aeec cpsr 80000070
I/DEBUG   (18110):            #00 pc 0000aeec /system/lib/libc.so
I/DEBUG   (18110):            #01 pc 000008e6 /system/lib/libstdc++.so
I/DEBUG   (18110):            #02 pc 00014124 /system/lib/libutils.so
I/DEBUG   (18110):            #03 pc 0001423c /system/lib/libutils.so
I/DEBUG   (18110):            #04 pc 0001af28 /system/lib/libbinder.so
I/DEBUG   (18110):            #05 pc 0001ba20 /system/lib/libbinder.so
I/DEBUG   (18110):            #06 pc 0001bcd6 /system/lib/libbinder.so
I/DEBUG   (18110):            #07 pc 00014236 /system/lib/libutils.so
I/DEBUG   (18110):            #08 pc 000293a6 /system/lib/libandroid_runtime.so
I/DEBUG   (18110):            #09 pc 000313ca /system/lib/libandroid_runtime.so
I/DEBUG   (18110):            #10 pc 0000ecb4 /system/lib/libdvm.so
I/DEBUG   (18110):            #11 pc 00038838 /system/lib/libdvm.so
I/DEBUG   (18110):            #12 pc 000139b8 /system/lib/libdvm.so
I/DEBUG   (18110):            #13 pc 00019338 /system/lib/libdvm.so
I/DEBUG   (18110):            #14 pc 00018804 /system/lib/libdvm.so
.
.
.
                                  Copyright © 2012CommonsWare, LLC
SIGSEGV
●   Doing NDK development?
    –   Might be core dump from your code
●   Repeatable across devices, or on Nexus?
    –   Probably a bug in Android
●   Only happens on certain ROM?
    –   Probably a bug in the ROM mod


                      Copyright © 2012CommonsWare, LLC
Getting Help
●   StackOverflow
    –   android tag
●   Google Hangouts by Android Developer
    Support
    –   QR code for YouTube archives
●   www.andglobe.com
    –   Q&A sites, organized by language

                      Copyright © 2012CommonsWare, LLC
Speaker Contact
    Information




       Copyright © 2012CommonsWare, LLC

Contenu connexe

En vedette

X dedic marketplace_eng
X dedic marketplace_engX dedic marketplace_eng
X dedic marketplace_engAndrey Apuhtin
 
Xi Epsilon September 2009 E Newsletter
Xi Epsilon September 2009 E NewsletterXi Epsilon September 2009 E Newsletter
Xi Epsilon September 2009 E Newsletterpjcorr
 
Xedapp demo - Excel sheet updates using Xedapp
Xedapp demo  - Excel sheet updates using XedappXedapp demo  - Excel sheet updates using Xedapp
Xedapp demo - Excel sheet updates using XedappXedapp
 
Xdd Evidence Storage
Xdd Evidence StorageXdd Evidence Storage
Xdd Evidence Storagecarriejo
 

En vedette (6)

XIV semana del Libro en Aguimes
XIV semana del Libro en AguimesXIV semana del Libro en Aguimes
XIV semana del Libro en Aguimes
 
Xilacina epidural
Xilacina epiduralXilacina epidural
Xilacina epidural
 
X dedic marketplace_eng
X dedic marketplace_engX dedic marketplace_eng
X dedic marketplace_eng
 
Xi Epsilon September 2009 E Newsletter
Xi Epsilon September 2009 E NewsletterXi Epsilon September 2009 E Newsletter
Xi Epsilon September 2009 E Newsletter
 
Xedapp demo - Excel sheet updates using Xedapp
Xedapp demo  - Excel sheet updates using XedappXedapp demo  - Excel sheet updates using Xedapp
Xedapp demo - Excel sheet updates using Xedapp
 
Xdd Evidence Storage
Xdd Evidence StorageXdd Evidence Storage
Xdd Evidence Storage
 

Similaire à X Means Y

Securing User Data with SQLCipher
Securing User Data with SQLCipherSecuring User Data with SQLCipher
Securing User Data with SQLCipherCommonsWare
 
KrankGeek November 2021 - Best practices in Electron-based desktop developmen...
KrankGeek November 2021 - Best practices in Electron-based desktop developmen...KrankGeek November 2021 - Best practices in Electron-based desktop developmen...
KrankGeek November 2021 - Best practices in Electron-based desktop developmen...Arnaud BUDKIEWICZ
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIOpersys inc.
 
GDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android NGDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android NImam Raza
 
Android Security: Defending Your Users
Android Security: Defending Your UsersAndroid Security: Defending Your Users
Android Security: Defending Your UsersCommonsWare
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VOpersys inc.
 
Android Platform Debugging and Development at ABS 2014
Android Platform Debugging and Development at ABS 2014Android Platform Debugging and Development at ABS 2014
Android Platform Debugging and Development at ABS 2014Opersys inc.
 
What's New in Jelly Bean
What's New in Jelly BeanWhat's New in Jelly Bean
What's New in Jelly BeanCommonsWare
 
Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Opersys inc.
 
Droidcon uk2012 androvm
Droidcon uk2012 androvmDroidcon uk2012 androvm
Droidcon uk2012 androvmdfages
 
Android Platform Debugging and Development at ELCE 2013
Android Platform Debugging and Development at ELCE 2013Android Platform Debugging and Development at ELCE 2013
Android Platform Debugging and Development at ELCE 2013Opersys inc.
 
Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15sullis
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UIOpersys inc.
 
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...Fabrice Bernhard
 
Building Multi-Channel Data-Aware Applications
Building Multi-Channel Data-Aware ApplicationsBuilding Multi-Channel Data-Aware Applications
Building Multi-Channel Data-Aware Applicationscjolif
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UIOpersys inc.
 

Similaire à X Means Y (20)

Android Development Tutorial V3
Android Development Tutorial   V3Android Development Tutorial   V3
Android Development Tutorial V3
 
Android Platform Debugging & Development
Android Platform Debugging & Development Android Platform Debugging & Development
Android Platform Debugging & Development
 
Securing User Data with SQLCipher
Securing User Data with SQLCipherSecuring User Data with SQLCipher
Securing User Data with SQLCipher
 
KrankGeek November 2021 - Best practices in Electron-based desktop developmen...
KrankGeek November 2021 - Best practices in Electron-based desktop developmen...KrankGeek November 2021 - Best practices in Electron-based desktop developmen...
KrankGeek November 2021 - Best practices in Electron-based desktop developmen...
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VI
 
GDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android NGDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android N
 
Android Security: Defending Your Users
Android Security: Defending Your UsersAndroid Security: Defending Your Users
Android Security: Defending Your Users
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon V
 
Android Platform Debugging and Development at ABS 2014
Android Platform Debugging and Development at ABS 2014Android Platform Debugging and Development at ABS 2014
Android Platform Debugging and Development at ABS 2014
 
What's New in Jelly Bean
What's New in Jelly BeanWhat's New in Jelly Bean
What's New in Jelly Bean
 
Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014
 
Droidcon uk2012 androvm
Droidcon uk2012 androvmDroidcon uk2012 androvm
Droidcon uk2012 androvm
 
Android Platform Debugging and Development at ELCE 2013
Android Platform Debugging and Development at ELCE 2013Android Platform Debugging and Development at ELCE 2013
Android Platform Debugging and Development at ELCE 2013
 
Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15
 
Codename one
Codename oneCodename one
Codename one
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UI
 
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
 
Building Multi-Channel Data-Aware Applications
Building Multi-Channel Data-Aware ApplicationsBuilding Multi-Channel Data-Aware Applications
Building Multi-Channel Data-Aware Applications
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UI
 
Android a brief intro
Android a brief introAndroid a brief intro
Android a brief intro
 

Plus de CommonsWare

Gradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsGradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsCommonsWare
 
Getting Android Developers for Your Wearables
Getting Android Developers for Your WearablesGetting Android Developers for Your Wearables
Getting Android Developers for Your WearablesCommonsWare
 
When Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsWhen Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsCommonsWare
 
The Action Bar: Front to Back
The Action Bar: Front to BackThe Action Bar: Front to Back
The Action Bar: Front to BackCommonsWare
 
Secondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerSecondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerCommonsWare
 
Mastering the Master Detail Pattern
Mastering the Master Detail PatternMastering the Master Detail Pattern
Mastering the Master Detail PatternCommonsWare
 
Not Quite As Painful Threading
Not Quite As Painful ThreadingNot Quite As Painful Threading
Not Quite As Painful ThreadingCommonsWare
 
Android Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewAndroid Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewCommonsWare
 
Maps V2... And You!
Maps V2... And You!Maps V2... And You!
Maps V2... And You!CommonsWare
 
A Deep Dive Into ViewPager
A Deep Dive Into ViewPagerA Deep Dive Into ViewPager
A Deep Dive Into ViewPagerCommonsWare
 
Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2CommonsWare
 
Integrate Android Apps and Web Apps
Integrate Android Apps and Web AppsIntegrate Android Apps and Web Apps
Integrate Android Apps and Web AppsCommonsWare
 
From Android to the Mobile Web
From Android to the Mobile WebFrom Android to the Mobile Web
From Android to the Mobile WebCommonsWare
 
The Wonderful World of Wearables
The Wonderful World of WearablesThe Wonderful World of Wearables
The Wonderful World of WearablesCommonsWare
 
Beaming Data to Devices with NFC
Beaming Data to Devices with NFCBeaming Data to Devices with NFC
Beaming Data to Devices with NFCCommonsWare
 
Making Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsMaking Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsCommonsWare
 
AppsWorld Keynote
AppsWorld KeynoteAppsWorld Keynote
AppsWorld KeynoteCommonsWare
 
App Integration (Revised and Updated)
App Integration (Revised and Updated)App Integration (Revised and Updated)
App Integration (Revised and Updated)CommonsWare
 
Rich Text Editing and Beyond
Rich Text Editing and BeyondRich Text Editing and Beyond
Rich Text Editing and BeyondCommonsWare
 
App integration: Strategies and Tactics
App integration: Strategies and TacticsApp integration: Strategies and Tactics
App integration: Strategies and TacticsCommonsWare
 

Plus de CommonsWare (20)

Gradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsGradle and Your Android Wearable Projects
Gradle and Your Android Wearable Projects
 
Getting Android Developers for Your Wearables
Getting Android Developers for Your WearablesGetting Android Developers for Your Wearables
Getting Android Developers for Your Wearables
 
When Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsWhen Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable Apps
 
The Action Bar: Front to Back
The Action Bar: Front to BackThe Action Bar: Front to Back
The Action Bar: Front to Back
 
Secondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerSecondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManager
 
Mastering the Master Detail Pattern
Mastering the Master Detail PatternMastering the Master Detail Pattern
Mastering the Master Detail Pattern
 
Not Quite As Painful Threading
Not Quite As Painful ThreadingNot Quite As Painful Threading
Not Quite As Painful Threading
 
Android Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewAndroid Development: The 20,000-Foot View
Android Development: The 20,000-Foot View
 
Maps V2... And You!
Maps V2... And You!Maps V2... And You!
Maps V2... And You!
 
A Deep Dive Into ViewPager
A Deep Dive Into ViewPagerA Deep Dive Into ViewPager
A Deep Dive Into ViewPager
 
Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2
 
Integrate Android Apps and Web Apps
Integrate Android Apps and Web AppsIntegrate Android Apps and Web Apps
Integrate Android Apps and Web Apps
 
From Android to the Mobile Web
From Android to the Mobile WebFrom Android to the Mobile Web
From Android to the Mobile Web
 
The Wonderful World of Wearables
The Wonderful World of WearablesThe Wonderful World of Wearables
The Wonderful World of Wearables
 
Beaming Data to Devices with NFC
Beaming Data to Devices with NFCBeaming Data to Devices with NFC
Beaming Data to Devices with NFC
 
Making Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsMaking Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business Models
 
AppsWorld Keynote
AppsWorld KeynoteAppsWorld Keynote
AppsWorld Keynote
 
App Integration (Revised and Updated)
App Integration (Revised and Updated)App Integration (Revised and Updated)
App Integration (Revised and Updated)
 
Rich Text Editing and Beyond
Rich Text Editing and BeyondRich Text Editing and Beyond
Rich Text Editing and Beyond
 
App integration: Strategies and Tactics
App integration: Strategies and TacticsApp integration: Strategies and Tactics
App integration: Strategies and Tactics
 

X Means Y

  • 1. Samsung Developer Office Hours NYC X Means Y: Interpreting the Development Tools Copyright © 2012CommonsWare, LLC
  • 2. 01-03 01:32:11.986: E/AndroidRuntime(17991): Caused by: android.os.NetworkOnMainThreadException Copyright © 2012CommonsWare, LLC
  • 3. StrictMode ● Reports obvious long-running stuff on main application thread ● Network I/O automatically reported on Android 3.0+ – Do not disable the error – fix the problem! – Opt-in for Android 2.3 ● Can also configure to report disk I/O on main thread, failure to close files/databases/cursors, etc. Copyright © 2012CommonsWare, LLC
  • 5. 06-29 23:11:17.796: I/Choreographer(691): Skipped 18 frames! The application may be doing too much work on its main thread. Copyright © 2012CommonsWare, LLC
  • 6. Choreographer ● Information Message in LogCat – “Skipped N frames” * 16ms = amount of time you took on main application thread – The more frames skipped, the more likely it is the user will notice ● UI frozen and not responsive ● Animation/scrolling hiccups – Android 4.1+ Copyright © 2012CommonsWare, LLC
  • 7. Project Butter ● UI Updates @ 60 frames/second ● Objective: smoother UI updates – Especially animations ● Transparent to developers – No code changes to “opt into” Butter effects ● Google I/O 2012: “For Butter or Worse” Copyright © 2012CommonsWare, LLC
  • 8. Project Butter Ramifications ● Only ~16ms Per Frame – Your code on the main application thread – Framework code – Other interruptions (e.g., background process) ● Net: Get Off the Main Application Thread! – Anything taking more than a few milliseconds needs to move to background thread or be executed incrementally Copyright © 2012CommonsWare, LLC
  • 9. 12-12 08:56:20.746: E/AndroidRuntime(1570): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() Copyright © 2012CommonsWare, LLC
  • 10. Looper and Handler ● Queuing mechanism ● Used by main application thread ● Error results from trying to do wrong thing on background thread – setContentView() – requestLocationUpdates() ● HandlerThread Copyright © 2012CommonsWare, LLC
  • 11. java.lang.StackOverflowError at android.widget.TextView.onDraw(TextView.java:4329) at android.view.View.draw(View.java:6993) at android.view.ViewGroup.drawChild(ViewGroup.java:1732) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459) at android.view.View.draw(View.java:6996) at android.view.ViewGroup.drawChild(ViewGroup.java:1732) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459) at android.view.View.draw(View.java:6996) at android.view.ViewGroup.drawChild(ViewGroup.java:1732) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459) at android.view.View.draw(View.java:6996) at android.view.ViewGroup.drawChild(ViewGroup.java:1732) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459) at android.view.View.draw(View.java:6996) at android.view.ViewGroup.drawChild(ViewGroup.java:1732) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459) . . . Copyright © 2012CommonsWare, LLC
  • 12. StackOverflowError ● Your code? – Too-deep recursion ● View/ViewGroup code? – Too-complex UI: nested containers – 8KB stack space on main application thread Copyright © 2012CommonsWare, LLC
  • 13. StackOverflowError ● Diagnostics – Open UI in emulator ● Or device if you embed ViewServer in it – Run Hierarchy View ● Eclipse perspective or via monitor – Count depth – Find stuff safe to eliminate ● Containers with only one child Copyright © 2012CommonsWare, LLC
  • 15. OutOfMemoryError ● Limited heap sizes – 16-64MB, depending on OS version and device capabilities ● Non-compacting garbage collector – Cannot allocate a block big enough for your request ● Primary culprit: bitmaps – 1080p image = ~8MB Copyright © 2012CommonsWare, LLC
  • 16. OutOfMemoryError ● Diagnostics – MAT ● Dump heap (HPROF) using Debug or DDMS ● Load into MAT (Eclipse plug-in or standalone) ● Hunt for culprits – adb shell dumpsys meminfo ● Lots of low-level information ● Difficult to accurately interpret Copyright © 2012CommonsWare, LLC
  • 17. OutOfMemoryError ● BitmapFactory.Options – inSampleSize: downsample for less heap use – inPurgeable/inInputShareable: for sharing backing data for mutations of common ancestor bitmap – inBitmap: for reusing existing Bitmap buffer ● Must be of the same dimensions and bit depth ● Maintain your own object pools versus fragmenting your heap Copyright © 2012CommonsWare, LLC
  • 18. I/DEBUG (18110): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** I/DEBUG (18110): Build fingerprint: 'MOTO_O2DE/umts_sholes/umts_sholes/sholes:2.1-... I/DEBUG (18110): pid: 23912, tid: 23913 >>> com.example.test <<< I/DEBUG (18110): signal 11 (SIGSEGV), fault addr 0000000c I/DEBUG (18110): r0 00140120 r1 00000048 r2 00000000 r3 00140168 I/DEBUG (18110): r4 afe3ae08 r5 00000006 r6 00140158 r7 0000a000 I/DEBUG (18110): r8 100ffcf8 r9 4185eef8 10 4185eee0 fp 001243b0 I/DEBUG (18110): ip 00000000 sp 100ffc50 lr afe0f130 pc afe0aeec cpsr 80000070 I/DEBUG (18110): #00 pc 0000aeec /system/lib/libc.so I/DEBUG (18110): #01 pc 000008e6 /system/lib/libstdc++.so I/DEBUG (18110): #02 pc 00014124 /system/lib/libutils.so I/DEBUG (18110): #03 pc 0001423c /system/lib/libutils.so I/DEBUG (18110): #04 pc 0001af28 /system/lib/libbinder.so I/DEBUG (18110): #05 pc 0001ba20 /system/lib/libbinder.so I/DEBUG (18110): #06 pc 0001bcd6 /system/lib/libbinder.so I/DEBUG (18110): #07 pc 00014236 /system/lib/libutils.so I/DEBUG (18110): #08 pc 000293a6 /system/lib/libandroid_runtime.so I/DEBUG (18110): #09 pc 000313ca /system/lib/libandroid_runtime.so I/DEBUG (18110): #10 pc 0000ecb4 /system/lib/libdvm.so I/DEBUG (18110): #11 pc 00038838 /system/lib/libdvm.so I/DEBUG (18110): #12 pc 000139b8 /system/lib/libdvm.so I/DEBUG (18110): #13 pc 00019338 /system/lib/libdvm.so I/DEBUG (18110): #14 pc 00018804 /system/lib/libdvm.so . . . Copyright © 2012CommonsWare, LLC
  • 19. SIGSEGV ● Doing NDK development? – Might be core dump from your code ● Repeatable across devices, or on Nexus? – Probably a bug in Android ● Only happens on certain ROM? – Probably a bug in the ROM mod Copyright © 2012CommonsWare, LLC
  • 20. Getting Help ● StackOverflow – android tag ● Google Hangouts by Android Developer Support – QR code for YouTube archives ● www.andglobe.com – Q&A sites, organized by language Copyright © 2012CommonsWare, LLC
  • 21. Speaker Contact Information Copyright © 2012CommonsWare, LLC