1

I got the following crash report in my App "ANR keyDispatchingTimedOut in ActivityManager". The logCat that generated is shown below. Can anyone tell me where the error is exactly occurring? I tried a lot but I am not able to reproduce the error again. It occurs once, after that it doesn't show although I haven't done anything to fix the error.

**Log Cat Report**

DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 SUSPENDED
| group="main" sCount=1 dsCount=0 obj=0x400281c0 self=0xce38
| sysTid=7464 nice=0 sched=0/0 cgrp=default handle=-1345006496
| schedstat=( 58625349214 2714690161 19132 )
at java.lang.String._getChars(String.java:~1041)
at java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:89)
at java.lang.StringBuilder.<init>(StringBuilder.java:96)
at in.plackal.lovecyclesfree.CycleManager.readNotesFromFile(CycleManager.java:1995)
at in.plackal.lovecyclesfree.CycleManager.readFromRegister(CycleManager.java:1717)
at in.plackal.lovecyclesfree.ActivityManager.onStart(ActivityManager.java:53)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
at android.app.Activity.performStart(Activity.java:3791)
at android.app.Activity.performRestart(Activity.java:3821)
at android.app.Activity.performResume(Activity.java:3826)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2114)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)

"DispatcherThread" prio=5 tid=8 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x406606e8 self=0x16a280
| sysTid=7744 nice=0 sched=0/0 cgrp=default handle=1378768
| schedstat=( 7404750 4921250 23 )
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:119)
at android.os.Looper.loop(Looper.java:117)
at android.os.HandlerThread.run(HandlerThread.java:60)

"Binder Thread #3" prio=5 tid=33 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x405cfb58 self=0x3e1f20
| sysTid=7610 nice=0 sched=0/0 cgrp=default handle=3996712
| schedstat=( 6275204 26755586 40 )
at dalvik.system.NativeStart.run(Native Method)

"WebViewWorkerThread" prio=5 tid=32 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x405b6b48 self=0x37ed10
| sysTid=7608 nice=1 sched=0/0 cgrp=default handle=3665480
| schedstat=( 95768014 64209212 111 )
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:119)
at android.os.Looper.loop(Looper.java:117)
at android.os.HandlerThread.run(HandlerThread.java:60)

"http19" prio=5 tid=31 WAIT
| group="main" sCount=1 dsCount=0 obj=0x405c4a30 self=0x37dac8
| sysTid=7607 nice=1 sched=0/0 cgrp=default handle=3660800
| schedstat=( 92166 313457 4 )
at java.lang.Object.wait(Native Method)
- waiting on <0x405f0640> (a android.net.http.RequestQueue)
at java.lang.Object.wait(Object.java:358)
at android.net.http.ConnectionThread.run(ConnectionThread.java:98)

"http18" prio=5 tid=30 WAIT
| group="main" sCount=1 dsCount=0 obj=0x405c4798 self=0x37c898
| sysTid=7606 nice=1 sched=0/0 cgrp=default handle=3656144
| schedstat=( 59249 73000 3 )
at java.lang.Object.wait(Native Method)
- waiting on <0x405f0640> (a android.net.http.RequestQueue)
at java.lang.Object.wait(Object.java:358)
at android.net.http.ConnectionThread.run(ConnectionThread.java:98)

"http17" prio=5 tid=29 WAIT
| group="main" sCount=1 dsCount=0 obj=0x405c45c0 self=0x37b650
| sysTid=7605 nice=1 sched=0/0 cgrp=default handle=3651464
| schedstat=( 63708 79043 4 )
at java.lang.Object.wait(Native Method)
- waiting on <0x405f0640> (a android.net.http.RequestQueue)
at java.lang.Object.wait(Object.java:358)
at android.net.http.ConnectionThread.run(ConnectionThread.java:98)

"http16" prio=5 tid=28 WAIT
| group="main" sCount=1 dsCount=0 obj=0x405c43e8 self=0x37a408
| sysTid=7604 nice=1 sched=0/0 cgrp=default handle=3646784
| schedstat=( 58542 109166 3 )
at java.lang.Object.wait(Native Method)
- waiting on <0x405f0640> (a android.net.http.RequestQueue)
at java.lang.Object.wait(Object.java:358)
at android.net.http.ConnectionThread.run(ConnectionThread.java:98)

"http15" prio=5 tid=27 WAIT
| group="main" sCount=1 dsCount=0 obj=0x405c4210 self=0x3791d8
| sysTid=7603 nice=1 sched=0/0 cgrp=default handle=3642128
| schedstat=( 64167 104083 3 )
at java.lang.Object.wait(Native Method)
- waiting on <0x405f0640> (a android.net.http.RequestQueue)
at java.lang.Object.wait(Object.java:358)
at android.net.http.ConnectionThread.run(ConnectionThread.java:98)
iknow
  • 8,358
  • 12
  • 41
  • 68
AndroidDev
  • 4,521
  • 24
  • 78
  • 126
  • What are you doing in your method? Is this heavy task? – Pankaj Kumar Feb 27 '12 at 06:08
  • Actually it read all the data that are saved in the file. Actually in this method i have read data that are save using shared preferences and the data that are save in file. – AndroidDev Feb 27 '12 at 06:18
  • You should move that task into another thread. read http://developer.android.com/resources/articles/painless-threading.html – Pankaj Kumar Feb 27 '12 at 06:29
  • Actually my function called on the onStart() method of the activityManager class which is my main thread. And this functions need to be called every time whenever the app start or whenever the user make changes from another activity and come back to this activity, so for this reason i write it on the onStart of the main activity. Now my question is how can i use the concept of thread on the onSatrt of the activity.Can u show me with an simple example. – AndroidDev Feb 27 '12 at 06:34
  • I have added a answer. See it. – Pankaj Kumar Feb 27 '12 at 07:26
  • Ok pnakaj i will go through this code..is it possible to reproduce the error again.. – AndroidDev Feb 27 '12 at 07:43
  • Yes you can. Try to go another activity and move back again and again until ANR doesn't. – Pankaj Kumar Feb 27 '12 at 07:55
  • Reason for this kind of error http://stackoverflow.com/questions/3467205/android-key-dispatching-timed-out/27292747#27292747 – Zar E Ahmer Dec 04 '14 at 11:23

2 Answers2

1

You can implement your method as

onStart method

@Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();

        doLongerTask();
    }

Method which will take long time to do process

private void doLongerTask() {
        final ProgressDialog dialog = ProgressDialog.show(Client.this, "Please wait", "Doing long task...", true);
        dialog.setCancelable(true);
        //dialog = CustomProgressDialog.show(this, "", "");
        new Thread() {
            @Override
            public void run() {
                try{
                    //TODO Write here your method logic
                    sleep(5000);
                } catch (Exception e) {  
                    Log.i("your_app_tag", e.toString());
                    dialog.dismiss();
                } 
                //Dismiss dialog, and notify handler to done this task
                dialog.dismiss();
                longTaskHandler.sendEmptyMessage(0);
           }
       }.start();    
    }

Handler which will handle UI changes after finishing long process.

private Handler longTaskHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            switch(msg.what) {
            case 0:
                //Here you can implement UI code. like if you are using listview
                //then you can refresh listview. 
                break;
            }                           
        }
    };

This is not only one way. Read here to know all possible ways.

Happy coding :)

Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
0

Check your method: in.plackal.lovecyclesfree.CycleManager#readNotesFromFile. Do it need a long time to finish it, could do it in the thread.

Hai Bo Wang
  • 632
  • 3
  • 6