Your activities are indeed classes. Look at the declarations!
public class MainActivity extends Activity {
^^^^^
// see? it's a class!
And the class is in whatever package it says on the top of the file. e.g.
package com.example.myapp;
every new activity has it’s own XML
I guess this is where you are most confused. The XML file is just a resource file. It’s just a description of the components in an activity. XML files like that are usually located in something like the app/src/main/res/layout/
folder. They are not classes.
So how are the XML file and your Activity
subclass linked together. The answer lies here:
setContentView (R.layout.activity_main);
Go to your Activity
subclass’s onCreate
method, you will find a line like the above. R.layout.activity_main
refers to the XML file. This line is when your activity class reads the XML file and loads the views contained in that file and set it as the content view. The R
class here is automatically generated by Android Studio and it contains references to your resources.
0
solved Is an activity a class