6

In my Android application I am getting a very strange crash randomly. When I open the application I am fetching data from server on splash screen. When the application land on home page suddenly whole application is closed and here is what gets printed in the log:

ANR in com.test (com.test/.activities.SplashActivity)
    PID: 16020
    Reason: Input dispatching timed out (49abf6 com.test/com.test.activities.SplashActivity (server) is not responding. Waited 5004ms for FocusEvent(hasFocus=false))
Parent: com.test/.activities.SplashActivity
    Load: 29.87 / 30.79 / 30.77
    ----- Output from /proc/pressure/memory -----
    some avg10=0.00 avg60=0.00 avg300=0.00 total=3115344
    full avg10=0.00 avg60=0.00 avg300=0.00 total=1338179
    ----- End output from /proc/pressure/memory -----
Amitanshu Gupta
  • 61
  • 1
  • 1
  • 4
  • Network call and I/O operation like heavy operation not in main thread. Use network lib retrofit and you can use coroutine. – Hemantvc Jun 16 '22 at 08:56
  • I am already using retrofit. Can you help me with an example using coroutine? @Hemantvc – Amitanshu Gupta Jun 16 '22 at 09:54
  • Find simple example of network call, https://camposha.info/android-examples/android-retrofit-coroutines/#gsc.tab=0 https://github.com/hemantvc/kotlin-retrofit/blob/main/app/src/main/java/org/hariom/kotlin_retrofit/NewsService.kt – Hemantvc Jun 16 '22 at 10:24

1 Answers1

3

The cause of this exception is that UI thread is blocked and your application is not responding for more than 5 seconds.

Double check that the code fetching data from server is not executed on main thread. Also if you are using a braodcast receiver to do any logic that could take 10 seconds will lead to this issue.

Something else to check is the exception handling in the code fetching data from server.

You can take a look at the following page also: https://developer.android.com/training/articles/perf-anr.html#anr

mabulazm
  • 41
  • 3
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/33211590) – Antoine Nov 23 '22 at 07:12