Android Activity

As we know activities are the UI screens for the android application. A single application can have n number of activities. Earlier we worked on single activity i.e. our main activity. In this example we are going to create another activity and call it from main activity on button click.

For this add android project and add button on main activity. Create a method in java file and map it with button on click.

public void btn_OpenActivity(View v)
{
    
    
    
}

		

First of all add java file for another activity by right clicking on following given selected folder inside java.

		android activity
		Figure 1
		

Give a proper name to the activity

		
		give name to the activity
		Figure 2
		

Now go to the layout folder and add an XML file as every activity associated with XML file.

	add layout
		Figure 3
		

Now give a proper name to the activity

		give name to the layut
		Figure 4
		

After click on ok you will get another file. Now you have to go in the manifest file and add the reference of this activity where main activity is already added

		android manifest
		Figure 5
		

Now go to the btn_click and open the new activity which we have created

		public void btn_OpenActivity(View v)
    {
startActivity(new Intent(MainActivity.this,AnotherActivity.class));


    }

		

Now go to the AnotherActivity java file and add following code

		public class AnotherActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_another);
    }
}


		

Now execute the code

Email Address

For any query you can send mail at info@techaltum.com