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?
-
where is your code and logcat??? – M D Apr 01 '15 at 09:40
-
i edited question to attach the log. – Jyothish Apr 01 '15 at 09:52
-
information inaccuracy and miscellaneous. – SilentKnight Apr 01 '15 at 09:56
4 Answers
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.

- 13,761
- 19
- 49
- 78
-
Hi, I remember reading something similar in the Android documentation, but I can not find it anymore, can you please send me the link? – dmarin Jul 11 '17 at 06:46
-
1@dmarin Link is here: https://developer.android.com/training/articles/perf-anr.html – SilentKnight Jul 12 '17 at 02:34
-
-
2@dmarin if you look up in source codes, you would see `// How long we wait for a service to finish executing. static final int SERVICE_TIMEOUT = 20*1000; // How long we wait for a service to finish executing. static final int SERVICE_BACKGROUND_TIMEOUT = SERVICE_TIMEOUT * 10;` in line 90~94. And in line 1783~1791 of `ActivityManagerService`, you would see `mHandler.sendMessageDelayed(nmsg, ActiveServices.SERVICE_TIMEOUT);` – SilentKnight Jul 12 '17 at 12:16
ANR occurs when Android detects the system is unable to respond to user input for more than a few seconds.
CursorWindow﹕ Window is full: requested allocation 396488 bytes,
free space 285853 bytes, window size 2097152 bytes
04-01 05:32:34.328 1598-1607/com.inxed W/CursorWrapperInner﹕
Cursor finalized without prior close()
you need to close the cursor.

- 1,706
- 1
- 18
- 39
-
on the on resume of main activity I call two async tasks back to back – Jyothish Apr 01 '15 at 09:53
It looks like your DB cursor its full. After saving data from the cursor, close it, set it to null and create a new one so no buffers are kept in memory.

- 1
- 1

- 5,225
- 3
- 32
- 45