How to connect two activities in Android?

Define onClick attribute of button with function to be called as value of the attribute.

<Button
....
android:onClick = login
/>

 where login is the name of function that is called when button is clicked.

 Now define Intent object inside this login() function.

Intent myIntent = new Intent( this, DashBoard.class);
startActivity(myIntent);

 You need to add second activity name in AndroidManifest.xml file to make operating system know about the existence of second activity.

  <activity
     android:name=".DashBoard"
     android:label="@string/app_name"
   />

This is step that we usually forget to do. So keep in mind.

Advertisements

About Priyanka Kapoor

Simple, Hardworking & friendly.....
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s