Search code examples
androidlogcatandroid-logcat

is the invalidate() function of View class a blocking function? [or, does the logcat show log messages out of order?]


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?


Solution

  • As Blocking methods are those which blocks the current executing thread from further operation until function returns. So as you view can be complex or may take alot of time to redraw or update when you call invalidate, so in Android OS View.invalidate tells the system to redraw (via onDraw) the view as soon as the main thread goes idle. That is, calling invalidate schedules your view to be redrawn after all other immediate work has finished.

    Hope this helps