how to fix Application not responding?

后端 未结 1 859
迷失自我
迷失自我 2021-01-19 08:25

i have prepared paint application,my application contains one custom view for paint.when we draw any thing in custom view just collect the drawn pixels and store in array li

相关标签:
1条回答
  • 2021-01-19 08:50

    Your application is bound to get "Application not responding" errors since you're doing all your computation, including allocation in the UI thread (onDraw).

    Firstly, you should try moving the computations into a non-ui thread (see AsyncTask). Any operation that is taking more than 20ms is bound to invoke the "Application Not responding" message.

    Secondly, you should try and refactor your code such that you do not have to perform the computation every time you have to draw. Basically render your image is an off screen bitmap, cache it and render it from the cached copy in onDraw. The scope of "how to", I'm afraid, is beyond the scope of this discussion.

    0 讨论(0)
提交回复
热议问题