本文介绍了ANR keyDispatchingTimedOut在ActivityManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我在我的应用程序ANR keyDispatchingTimedOut在ActivityManager得到了下面的崩溃报告。生成该logcat的如下所示。谁能告诉我在哪里,也正是发生错误。我试过很多,但我不能够再次重现错误。它发生一次,之后它不显示虽然我没有做任何事情来修复错误。

  **登录猫报告**DALVIK主题:
(互斥:TLL = 0 TSL = 0 TSCL = 0 GHL = 0和黄= 0 hwll = 0)
主PRIO = 5 TID = 1悬
|组=主SCOUNT = 1 dsCount = 0 = OBJ自我0x400281c0 = 0xce38
| sysTid = 7464 =不错附表0 = 0/0 = CGRP默认手柄= -1345006496
| schedstat =(58625349214 2714690161 19132)
在java.lang.String._getChars(String.java:~1041)
在java.lang.AbstractStringBuilder<&初始化GT;(AbstractStringBuilder.java:89)
在java.lang.StringBuilder中的<&初始化GT;(StringBuilder.java:96)
在in.plackal.lovecyclesfree.CycleManager.readNotesFromFile(CycleManager.java:1995)
在in.plackal.lovecyclesfree.CycleManager.readFromRegister(CycleManager.java:1717)
在in.plackal.lovecyclesfree.ActivityManager.onStart(ActivityManager.java:53)
在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
在android.app.Activity.performStart(Activity.java:3791)
在android.app.Activity.performRestart(Activity.java:3821)
在android.app.Activity.performResume(Activity.java:3826)
在android.app.ActivityThread.performResumeActivity(ActivityThread.java:2114)
在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:961)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:130)
在android.app.ActivityThread.main(ActivityThread.java:3691)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:507)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:847)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
在dalvik.system.NativeStart.main(本机方法)DispatcherThreadPRIO = 5 TID = 8 NATIVE
|组=主SCOUNT = 1 dsCount = 0 = OBJ自我0x406606e8 = 0x16a280
| sysTid = 7744 =不错附表0 = 0/0 = CGRP默认手柄= 1378768
| schedstat =(7404750 4921250 23)
在android.os.MessageQueue.nativePollOnce(本机方法)
在android.os.MessageQueue.next(MessageQueue.java:119)
在android.os.Looper.loop(Looper.java:117)
在android.os.HandlerThread.run(HandlerThread.java:60)捆扎线#3PRIO = 5 TID = 33 NATIVE
|组=主SCOUNT = 1 dsCount = 0 = OBJ自我0x405cfb58 = 0x3e1f20
| sysTid = 7610 =不错附表0 = 0/0 = CGRP默认手柄= 3996712
| schedstat =(6275204 26755586 40)
在dalvik.system.NativeStart.run(本机方法)WebViewWorkerThreadPRIO = 5 TID = 32 NATIVE
|组=主SCOUNT = 1 dsCount = 0 = OBJ自我0x405b6b48 = 0x37ed10
| sysTid = 7608 =不错附表1 = 0/0 = CGRP默认手柄= 3665480
| schedstat =(95768014 64209212 111)
在android.os.MessageQueue.nativePollOnce(本机方法)
在android.os.MessageQueue.next(MessageQueue.java:119)
在android.os.Looper.loop(Looper.java:117)
在android.os.HandlerThread.run(HandlerThread.java:60)http19PRIO = 5 TID = 31 WAIT
|组=主SCOUNT = 1 dsCount = 0 = OBJ自我0x405c4a30 = 0x37dac8
| sysTid = 7607 =不错附表1 = 0/0 = CGRP默认手柄= 3660800
| schedstat =(92166 313457 4)
在java.lang.Object.wait(本机方法)
- 等待针对<&0x405f0640 GT; (一android.net.http.RequestQueue)
在java.lang.Object.wait(Object.java:358)
在android.net.http.ConnectionThread.run(ConnectionThread.java:98)http18PRIO = 5 TID = 30 WAIT
|组=主SCOUNT = 1 dsCount = 0 = OBJ自我0x405c4798 = 0x37c898
| sysTid = 7606 =不错附表1 = 0/0 = CGRP默认手柄= 3656144
| schedstat =(59249 73000 3)
在java.lang.Object.wait(本机方法)
- 等待针对<&0x405f0640 GT; (一android.net.http.RequestQueue)
在java.lang.Object.wait(Object.java:358)
在android.net.http.ConnectionThread.run(ConnectionThread.java:98)http17PRIO = 5 TID = 29 WAIT
|组=主SCOUNT = 1 dsCount = 0 = OBJ自我0x405c45c0 = 0x37b650
| sysTid = 7605 =不错附表1 = 0/0 = CGRP默认手柄= 3651464
| schedstat =(63708 79043 4)
在java.lang.Object.wait(本机方法)
- 等待针对<&0x405f0640 GT; (一android.net.http.RequestQueue)
在java.lang.Object.wait(Object.java:358)
在android.net.http.ConnectionThread.run(ConnectionThread.java:98)http16PRIO = 5 TID = 28 WAIT
|组=主SCOUNT = 1 dsCount = 0 = OBJ自我0x405c43e8 = 0x37a408
| sysTid = 7604 =不错附表1 = 0/0 = CGRP默认手柄= 3646784
| schedstat =(58542 109166 3)
在java.lang.Object.wait(本机方法)
- 等待针对<&0x405f0640 GT; (一android.net.http.RequestQueue)
在java.lang.Object.wait(Object.java:358)
在android.net.http.ConnectionThread.run(ConnectionThread.java:98)http15PRIO = 5 TID = 27 WAIT
|组=主SCOUNT = 1 dsCount = 0 = OBJ自我0x405c4210 = 0x3791d8
| sysTid = 7603 =不错附表1 = 0/0 = CGRP默认手柄= 3642128
| schedstat =(64167 104083 3)
在java.lang.Object.wait(本机方法)
- 等待针对<&0x405f0640 GT; (一android.net.http.RequestQueue)
在java.lang.Object.wait(Object.java:358)
在android.net.http.ConnectionThread.run(ConnectionThread.java:98)


解决方案

您可以实现您的方法

OnStart方法

  @覆盖
    保护无效调用onStart(){
        // TODO自动生成方法存根
        super.onStart();        doLongerTask();
    }

方式,这将需要很长时间做处理

 私人无效doLongerTask(){
        最后ProgressDialog对话框= ProgressDialog.show(Client.this,请稍候,做长期的任务......,真);
        dialog.setCancelable(真);
        //对话框= CustomProgressDialog.show(这一点,,);
        新的Thread(){
            @覆盖
            公共无效的run(){
                尝试{
                    // TODO写到这里你的方法逻辑
                    睡眠(5000);
                }赶上(例外五){
                    Log.i(your_app_tag,e.toString());
                    dialog.dismiss();
                }
                //辞退对话框,并通知处理程序来完成这个任务
                dialog.dismiss();
                longTaskHandler.sendEmptyMessage(0);
           }
       }。开始();
    }

处理器完成漫长的过程之后,将处理用户界面的变化。

 专用处理器longTaskHandler =新的处理程序(){
        @覆盖
        公共无效的handleMessage(消息MSG){            开关(msg.what){
            情况下0:
                //在这里,您可以实现UI code。如果你正在使用类似的ListView
                //然后就可以刷新列表视图。
                打破;
            }
        }
    };

此不仅一种方式。阅读知道所有可能的方式。

快乐编码:)

Actually 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 occur. I tried lot but i am not able to reproduce the error again. It occurs once, after that it doesnt 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)
解决方案

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 :)

这篇关于ANR keyDispatchingTimedOut在ActivityManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 09:45