Launch a new Activity by using Intent in Android.
This public method launches a new Activity
and use an Intent
. An Intent is an object that provides runtime binding between separate components (such as two activities). The system receives this call and starts an instance of the Activity specified by the Intent. You will not receive any information about when the activity exits.
For example, you are in ActivityA and want to launch ActivityB. You do as follows:
// Create a new intent with current activity and new activity
Intent intent = new Intent(Activity1.this, ActivityB.class);
// Call startActivity to launch the new activity with intent
startActivity(intent);
An Intent can pass datas to new Activity, see Start the Second Activity topic from Google Documentation. Also, you can use the method startActivity(Intent, Bundle)
where Bundle
is additional options for how the Activity should be started.
Note: You must declare the new activity in your Manifest
file as the old one, like the following example:
<activity
android:label="@string/app_name"
android:name="com.package.name.ActivityB" />
About this method, see the startActivity(Intent intent) Documentation
And the SO question How to start new activity on button click
Related tags: android,
android-activity,
android-intent, bundle