How to debug Android ANR?

前端 未结 1 871
梦毁少年i
梦毁少年i 2021-02-02 15:56

My Android app gets a lot of ANR reports lately in the Google Play console. Since this started to happen when I included Google Analytics in the app, I strongly suspect Analytic

相关标签:
1条回答
  • 2021-02-02 16:45

    But how to know where it is blocked?

    Start by enabling StrictMode and running your app. If you (or Analytics) are doing disk or network I/O on the main application thread, you will find out about it, based upon your chosen penalty style (e.g., log in LogCat):

    public void onCreate() {
         if (BuildConfig.DEBUG) {
             StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                     .detectAll()
                     .penaltyLog()
                     .build());
         }
    
         super.onCreate();
    
         // rest of onCreate() logic here
     }
    
    0 讨论(0)
提交回复
热议问题