Android Paint multi-threaded environment graphics for a while to show no problem

Source: Internet
Author: User

Scenario Description:

Recently in the process of drawing stock time chart, encountered a problem, with the Android canvas after drawing, the viewpager between the back and forth (data request when switching, data request to draw after the graphics), the graphics will be hidden, for a moment display. This phenomenon makes me very frustrating, but finally through their own efforts, finally solved the problem, and now will solve the problem of the process and analysis of ideas to record.

Analyze and solve problems:

1, the initial suspicion is that the data is not obtained, so the graphics do not come out, however, after debugging breakpoints, found that this is not the problem, the data has been obtained intact, and there is no exception.

2, next doubt whether the data is populated, you need to do a refresh of the interface view, but the question is, why some time can come out, and sometimes do not show it.

3, the next suspicion of multi-threaded interaction, when the data obtained through the sub-thread, immediately after drawing graphics, drawing good graphics, the view may not be immediately displayed, so this time need to refresh, then use which Refresh method? Using invalidate () is obviously only suitable for view refresh in the main thread, while the Postinvalidate () method is suitable for the main thread refresh and the child thread refreshes, so I draw the data through canvas to the view after the child thread acquires the data. It is then immediately refreshed with the Postinvalidate () method, resulting in a problem resolution.

Android Paint multi-threaded environment shape a moment to show no problem

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.