Android fundamentals
Understand activities, layouts, and the app lifecycle.
An activity hosts a screen
An Activity is an Android component. In a Views app, onCreate prepares the screen and setContentView loads its XML layout. Android may recreate the activity, so fields alone are not permanent storage.
IDs connect XML to Java
Declare an ID in XML, load that layout, and then look up the view. The example assumes a TextView with the ID counter exists in the activity’s layout.
TextView label = findViewById(R.id.counter);
label.setText("Ready to build");State has different lifetimes
Use saved instance state or a ViewModel for appropriate screen state. Use persistent storage for information that must survive app restarts.
Try it yourself
Add a reset button to a counter screen. Rotate the device and explain which values should survive.


