Wicked161089
Wicked161089

Reputation: 481

Android Lollipop Application Not Responding

my App runs fine on Android 4.4 - 2.3. but I recently updated my Nexus 7 to Android 5.0.2 (Lollipop) and only here I get an Error / ANR. But I don't know why. I can't find anything related here or in the web.

The ANR appears, when I start an AsyncTask. It runs fine first and after 5 seconds, the UI Thread freezes and I get alot of ART Runtime Errors. Below I listed some ErrorLines which keep repeating:

02-19 10:12:23.060: A/art(7229): art/runtime/thread_list.cc:170] Thread suspend timeout
02-19 10:12:23.060: A/art(7229): art/runtime/thread_list.cc:170] DALVIK THREADS (27): 
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170] "ReferenceQueueDaemon" daemon prio=5 tid=7 Waiting
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   | group="system" sCount=1 dsCount=0 obj=0x12c26080 self=0xac59c000
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   | sysTid=7240 nice=0 cgrp=apps sched=0/0 handle=0xac598380
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   | state=S schedstat=( 0 0 0 ) utm=0 stm=2 core=3 HZ=100
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   | stack=0xb421f000-0xb4221000 stackSize=1036KB
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   | held mutexes=
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   at java.lang.Object.wait!(Native method)
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   - waiting on <0x063dedd6> (a java.lang.Class<java.lang.ref.ReferenceQueue>)
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   at java.lang.Daemons$ReferenceQueueDaemon.run(Daemons.java:133)
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   - locked <0x063dedd6> (a java.lang.Class<java.lang.ref.ReferenceQueue>)
02-19 10:12:23.061: A/art(7229): art/runtime/thread_list.cc:170]   at java.lang.Thread.run(Thread.java:818)

Same version of the app runs fine on all other APIs. Does Lollipop handles multitasking and wait() calls differently?

I hope anyone of you can help and maybe had a similar issue.

Thank you!

EDIT 1: Structure:

1: Click on UpdateButton starts AsyncTask which sends update requests to an Bluetooth device and waits for any incomming messages

2: Incomming Messages are stored in an MessageQueue (if this Queue is empty I call wait())

try {
    synchronized (myMessages) {
         myMessages.wait();
    }
} catch (InterruptedException ex) {
    return null;
}

3: if myMessages is not empty -> it sends an Update Intent to an BroadcastReceiver which updates a ListView

This repeats until the user clicks again on the UpdateButton. It works for about 5 seconds, then it freezes. There is no UI handling in the AsyncTask itself.

EDIT 2:

While debugging I get this really strange behaviour :D. I'll have my AsyncTask like described above: It's doInBackground Method looks like this:

@Override
protected String doInBackground(Void... params) {
     while(buttonClicked){
          // #POS: HERE IS THE STRANGE BEHAVIOR HAPPENING
          if(checkAnCondition){
                 doWork();
          }
     }
}

If I have the AsyncTask run in its while loop and there is nothing at #POS it throws the Application not Responding. During debugging I added a System.out.println("") Statement at this #POS and then.. The App runs fine :D WTF? :D

So.. Why does the app crashes if the first thing in the while statement is an if condition? Any Ideas?

Upvotes: 1

Views: 2928

Answers (2)

ayesh don
ayesh don

Reputation: 1161

Issue is on condition statement in the while loop.use more valid statement for this.

e.g queue is empty

Upvotes: 0

Carlos Verdes
Carlos Verdes

Reputation: 3157

The problem is that your are freezing a thread, it's not main thread so you have more "gap" before the ARN, but after 5 seconds... Android throws the error.

You could try to avoid blocking forever the thread checking each 3 seconds the queue (using timeout in your wait sentence), something like:

try {
    while( i have no messages){
        synchronized (myMessages) {
             myMessages.wait(300);
         }
    }
} catch (InterruptedException ex) {
return null;
}

I can't reproduce your error so... just let me know if this helps.

EDIT

I changed the while and timeout condition.

Upvotes: 1

Related Questions