Why do we call setContentView() in onCreate() ?
The first reason we do that, is because, we need a view for our activity, so that we can control our views using this activity be it the text views, the buttons or any other view, we might have defined. So since we know that we need to set our view somewhere, onCreate() is the best place for it, because, onCreate() gets called only once during the lifecycle of the activity.
Calling it in onResume() or onStart() will unnecessarily waste resources such as memory and CPU since they get called more than once. That is the main reason we do a lot of initializations in onCreate() which we know that they need to be created only once during the entire lifecycle of the activity.
About Me:
I began my professional journey when I was in my 6th Standard (2009) and have since worked on a number of solo and collaborative projects. I take pride in all that I do and in the long-term relationships I’ve fostered in the process. I firmly believe that hard work eventually pays off, and I know that each day brings me closer to reaching my goals. From small, solo projects to creative collaborations, I’m always looking for the chance to explore new venues and learn something new that I can apply to my work. Currently I am team SME and a Senior Software Engineer @Get My Parking having more than 4.5 years of professional Android development experience.
Additional Content to Consider:
Sign up on my website https://divyansh.co to join the most intellectual community.
For more advanced concepts on Jetpack Compose check out my course on Jetpack Compose https://www.divyansh.co/projects/courses
Subscribe to our YouTube channel for more videos about Kotlin, Android, Software Engineering, Career Growth and much more.
Business Enquires & Collaborations :
https://www.divyansh.co/book-online
Follow me on :
Instagram : / justdvnshof. .
Linkedin: / justdvnsh
Github: https://github.com/justdvnsh
Join my Discord server:
/ discord
My Coding Gear :
I use 2 Acer ED320QR Full HD VA Panel LED Curved Gaming Monitor with 165Hz Refresh Rate AMD Free Sync : https://www.amazon.in/gp/product/B08S...
Apple Magic Keyboard : https://www.amazon.in/Apple-Mac_Keybo...
Logitech MXMaster 3 : https://www.amazon.in/Logitech-MX-Mas...
Graphic Tablet : https://www.amazon.in/Huion-Graphics-...
Recording Gear :
iPhone 13: https://www.amazon.in/Apple-iPhone-13...