Android app not responding (ANR)

Jyothish picture Jyothish · Apr 1, 2015 · Viewed 13.9k times · Source

I have an android app, which listens to a socket from the server and retrieves data in json format and save data in the database. Resource cursor adapter is used to display the data in a list. When the app is idle for 10 minutes or more, it is not reponding. Any solutions?

Answer

SilentKnight picture SilentKnight · Apr 1, 2015

ANR occurs when the main thread is blocked for a few time. Specifically, 5 seconds in an Activity, 10 seconds in a BroadcastReceiver and 20 seconds in a Service. So, to avoid ANR, you need to ensure that you don't do something like these in you UI thread: reading or writing files, connecting the internet, operating databases and so on, which spend a lot of time. So, if you want to do things above, you may start a new thread to do that. Specifically, AsyncTask ThreadHandler and something like that.

I hope this will help you.