how to open new activity in android studio on button click code example

Example 1: how to move from one activity to another in android studio on button click

// also use set onclick listener
 public void next(View view) {
        Intent intent = new Intent(this,Activity2.class);
        startActivity(intent);
   }

Example 2: android how to start a new activity on button click

Intent intent = new Intent(this, ActivityToBeCalled.class);
startActivity(intent);

Example 3: how to open activity in android studio

Intent intent = new Intent(this, DisplayMessageActivity.class);
        intent.putExtra(key:,value:);
        startActivity(intent);

Tags:

Misc Example