1

I added the firebase cloud message to the app. I am calling a method in current activity when receiving a data message. The method include a volley post request.

The ANR occurring only in Huawei devices. I'm hoping there's someone who can give me an idea for it. Thanks.

The ANR stack:

Input dispatching timed out (Waiting to send key event because the focused window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: 0. Wait queue length: 2.)

    "main" tid=1 Native 
    "main" prio=5 tid=1 Native
      | group="main" sCount=1 dsCount=0 flags=1 obj=0x73056ad0 self=0x78122a3a00
      | sysTid=20046 nice=-10 cgrp=default sched=0/0 handle=0x78171f79b0
      | state=S schedstat=( 7479347944 793149495 9121 ) utm=657 stm=90 core=2 HZ=100
      | stack=0x7fff6b9000-0x7fff6bb000 stackSize=8MB
      | held mutexes=
      #00  pc 0000000000069800  /system/lib64/libc.so (__epoll_pwait+8)
      #01  pc 000000000001f6c0  /system/lib64/libc.so (epoll_pwait+48)
      #02  pc 0000000000015c80  /system/lib64/libutils.so (_ZN7android6Looper9pollInnerEi+144)
      #03  pc 0000000000015b68  /system/lib64/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+108)
      #04  pc 000000000011a5dc  /system/lib64/libandroid_runtime.so (???)
      #05  pc 00000000002014ac  /system/framework/arm64/boot-framework.oat (Java_android_os_MessageQueue_nativePollOnce__JI+140)
      at android.os.MessageQueue.nativePollOnce (MessageQueue.java)
      at android.os.MessageQueue.next (MessageQueue.java:379)
      at android.os.Looper.loop (Looper.java:144)
      at android.app.ActivityThread.main (ActivityThread.java:7523)
      at java.lang.reflect.Method.invoke (Method.java)
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
      at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)

Java code: The class of dEmptyOperation extend from AsyncTask. The method of refreshList include a volley post request

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
// .. if statement codes
                    new dEmptyOperation() {
                        @Override
                        protected String doInBackground(String... params) {
                            if (main.refreshActivity != null) {
                                try {
                                    main.refreshActivity.refreshList();
                                    main.refresh = false;
                                }catch (Exception ignored){

                                }
                            }
                            return null;
                        }
                    }.execute("");
//..
    }
Serdar Didan
  • 321
  • 3
  • 6

1 Answers1

0

I cannot say exactly what is happening without seeing your code. However, I think you are calling a method in your current activity which is doing intensive work in the main thread and that's the reason for most cases while you are having an ANR.

You can easily avoid this using an AsyncTask. Create an AsyncTask each time you are processing some data and handle the callbacks in your activity while the data is finished processing.

Here is a nice answer on how you can create an AsyncTask and handle the callbacks in your activity.

Hope that helps!

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98