ActivityManager中的ANR

ActivityManager中的ANR

实际上,我在应用程序“ ActivityManager中的ANR keyDispatchingTimedOut”中收到以下崩溃报告。生成的logCat如下所示。谁能告诉我错误的确切位置。我尝试了很多,但无法再次再现该错误。它发生一次,在那之后它没有显示,尽管我没有做任何事情来纠正错误。

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

最佳答案

您可以将您的方法实现为

onStart方法

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

        doLongerTask();
    }


需要很长时间才能完成的方法

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();
    }


完成长时间的处理后将处理UI更改的处理程序。

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;
            }
        }
    };


这不仅是一种方式。阅读here了解所有可能的方法。

快乐的编码:)

关于android - ActivityManager中的ANR keyDispatchingTimedOut,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9460525/

10-08 21:27