Android app not responding (ANR)

房东的猫 提交于 2019-12-14 00:28:05

问题


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?


回答1:


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.




回答2:


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.




回答3:


ANR display if application cannot respond to the user input.According to the Google doc,you should not perform the work on the UI thread. I recommend you to perform network request or long running operation in worker thread instead of UI thread. for more this




回答4:


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.

this SO answer gives more information



来源:https://stackoverflow.com/questions/39042942/android-anr-while-getting-instance-of-sslcontex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!