Android - Function is not completing

廉价感情. 提交于 2019-12-25 01:43:46

问题


I'm trying to get a string using a http call. I am noticing that in large files I am not reading all of the file before it stops and gives me this error and then continues with the rest of the script.

11-29 11:26:18.417: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock!
11-29 11:26:18.556: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{45059000 com.MeetingManager/.MeetingManager}

I feel like the getXML function is taking to long and the app just moves right along to the next line of code which uses the incomplete string from the previous function that did not finish. Of course this is making my app crap out.

How do I give my function more time?

Below are the two function calls. If you need more info from these calls just let me know.

String xml = XMLfunctions.getXML(items); Document doc = XMLfunctions.XMLfromString(xml);


回答1:


It looks like you're calling a long running function inside your application's onCreate or onResume methods which is blocking the main application thread. This isn't a good idea as it means your users won't be able to see information if the app takes a long time to start up - they might think nothing is happening and quit.

Have a look at this and move any long running operations into something like an ASyncTask or a Thread with a Handler. Have a look here for more information.



来源:https://stackoverflow.com/questions/8315928/android-function-is-not-completing

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