Move from one activity to another activity in android

We have see some tutorial with single screen in android. Of course in development all applications with multiple screen. So it’s necessary to switch from one activity to another with some user click on any view.

Using Intent we can achieve this thing. See below code.

In Intent constructor we have to pass two parameters. First one Context of current activity and second one is Activity class we have start. Here you can also replace MainActivity.this to context  . After that we can start new activity by startActivity(intent).

Let’s see one example. Create two activity called MainActivity and SecondActivity with their layout xml file.


and second_activity.xml

Now in our class

and for

Now most important part of this project is declaring second activity in our AndroidManifest.xml  file. Actually we have to declare all activity in this file.

Here <intent-filter> is used to declare which activity is start first.

Now Run project. Our output look like this.


Download Project.


You may also able to pass some data from one activity to another activity using Intent. Let’s see next Post for Pass data from one activity to another using Intent.