Android Development stepped in the pit of the four: low version using Asynctask

Source: Internet
Author: User

This hole is more obscure, generally not easy to appear.


It is possible to set the UI in the Postresult () method when using Asynctask, but to be told that the UI exception cannot be set on a non-UI thread.

This actually applies a bug when the app is launched. Asynctask is at the time of initialization, take the current thread to get looper. But here 's the problem.

The current thread may not be the UI thread, so it causes the Postresult () to work in the UI thread, and so on, actually in a non-UI thread.

Google resolved this bug in the 4.1 release, that is, when the app starts, it first calls the Asynctask.init () at the UI line thread. So in the current application, Asynctask's looper is the UI thread's Looper.

But in the previous version of 4.1, before using Asynctask, you could call Asynctask.init () in the UI thread yourself.

Android Development stepped in the pit of the four: low version using Asynctask

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.