Home » Android » view – Android setContentView operation

view – Android setContentView operation

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’ve read that it’s important to call setContentView() early in an activity since it builds the view objects that may be manipulated by subsequent code in onCreate().

In terms of lifecycle, does the view get drawn to screen as soon as setContentView() is called, or does it allow the onCreate() function to build/populate the information in the view objects, and wait to actually draw it after onCreate() completes?

Thanks!

How to&Answers:

does the view get drawn to screen as
soon as setContentView() is called

No.

or does it allow the onCreate()
function to build/populate the
information in the view objects, and
wait to actually draw it after
onCreate() completes?

Yes. The View objects are created immediately as part of setContentView(). However, all drawing operations (from onCreate() or anywhere else) really result in messages being put on a message queue that the main application thread works through.