[android] Android - how do I investigate an ANR?

You are wondering which task hold a UI Thread. Trace file gives you a hint to find the task. you need investigate a state of each thread

State of thread

  • running - executing application code
  • sleeping - called Thread.sleep()
  • monitor - waiting to acquire a monitor lock
  • wait - in Object.wait()
  • native - executing native code
  • vmwait - waiting on a VM resource
  • zombie - thread is in the process of dying
  • init - thread is initializing (you shouldn't see this)
  • starting - thread is about to start (you shouldn't see this either)

Focus on SUSPENDED, MONITOR state. Monitor state indicates which thread is investigated and SUSPENDED state of the thread is probably main reason for deadlock.

Basic investigate steps

  1. Find "waiting to lock"
    • you can find monitor state "Binder Thread #15" prio=5 tid=75 MONITOR
    • you are lucky if find "waiting to lock"
    • example : waiting to lock <0xblahblah> (a com.foo.A) held by threadid=74
  2. You can notice that "tid=74" hold a task now. So go to tid=74
  3. tid=74 maybe SUSPENDED state! find main reason!

trace does not always contain "waiting to lock". in this case it is hard to find main reason.