0

In this code,

Log.d("MYLOG", "i_confirm in Activity BEFORE = "+Integer.toString(i_confirm)); // LINE 1
theGraph.invalidate();
i_confirm = theGraph.ret_i_confirm(); // LINE 2  

the logcat shows the outputs due to the functions in line 1 and line 2 before showing me another logcat message that was inside the onDraw() function in theGraph, which extends View class. The above code is in my MainActivity class, inside a function that gets executed when a command button is pressed.

Is invalidate() a non blocking method? Does onDraw() and everything else inside invalidate() get called alongside the execution of the main program? Or is it possible for the logcat to show log messages out of order?

4

1 回答 1

1

因为阻塞方法是那些阻止当前正在执行的线程进一步操作直到函数返回的方法。因此,当您的视图可能很复杂或may take alot of time to redraw or update当您调用 invalidate 时,因此在 Android 操作系统中,View.invalidate 会告诉系统尽快重绘(通过 onDraw)视图the main thread goes idle。也就是说,调用 invalidate 会安排您的视图在所有其他直接工作完成后重绘。

希望这可以帮助

于 2013-09-17T10:26:48.013 回答