In this tutorial you'll learn how to navigate from Activity1 to Activity2 using a button.
1. Create 2 activities. (MainActivity & SecondActivity)
2. In the first Activity layout create a button.
3. In MainActivity.java add below bold codes:
public class MainActivity extends Activity implements OnClickListener {
Button next;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
next = (Button) findViewById(R.id.button1);
next.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
switch(arg0.getId()) {
case R.id.button1:
Intent myIntent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(myIntent);
break;
}
}
}
That's all.