It allows you to split the answer into two parts: XML and the JAVA part, since each action has each of these two. Assuming we have only two actions, "Activity1" is the one that has a button that redirects the user to "Activity2". Since we have 2 activities, we will have 4 files associated with these 2 actions.
XML
so first weβll make a simple way, as soon as you open the XML file Activity1, you should go to the design tab.
After reaching the constructive part, you can insert the button from the pallet, now you can select the button that is inside your layout. After selecting, you can see the properties of the button on the right side of the screen, where you can effectively change several properties of the button.
Here you will find the option "onClick", fill in the field next to it with something very simple or something that you can remember. For example, enter "nextAct"
or
The hard way is to manually enter the onClick property by entering the string follwing into the button code in XML
android:onClick="nextAct"
This is all part of XML.
Java
Open the .java Activity1 file, here you have to create a new method. This method should be called the same as in the "onClick" property of the button. Here I would take "nextAct" as this is what I used in XML. You can put this new method anywhere in the class of the java file, I prefer to store it at the end of the class, since I could easily find it if there is a problem in the future.
Now you need to write the body of the nextAct method. This can be summarized in these two lines.
public void nextAct(View v){ Intent i = new Intent(this, Activity2.class); startActivity(i); }
After that, both should be connected and working properly.