且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AsyncTask的onPostExecute()不会被调用+ W /艺术:暂停所有线程了:1.1ms

更新时间:2021-08-06 22:47:03

就叫新GetHtmlDocument(someUrlString)执行(); 并等待导致onPostExecute ()。没有必要while循环使用(即阻止你的UI线程),或致电取消()(实际上它不会做在默认情况下任何东西,在底部检查链接)。

Just call new GetHtmlDocument("someUrlString").execute(); and wait result in the onPostExecute(). There is no need to use while loop (that blocks your UI thread) or to call cancel() (actually it doesn't do anything by default, check link at the bottom).

请注意,

AsyncTask的应仅用于工作/这需要相当长几秒钟的操作;

AsyncTask should only be used for tasks/operations that take quite few seconds;

AsyncTasks在单个后台线程(从API​​ 11)串行执行。所以,长时间运行的工作人员可以阻止他人;

AsyncTasks are executed serially on a single background thread (from API 11). So long running worker can block others;

其他的一些陷阱的。