Tutorial – How to start a new Activity
For starting a new Activity we need to use intent, which is an abstract description of an operation to be performed.
http://developer.android.com/reference/android/content/Intent.html
Suppose we are on Activity named ‘CurrentActivity‘ and on certain event (like button click..) we want to start a new Activity named ‘NextActivity’
We can create a new activity as follows.
public class NextActivity extends Activity {
//Your member variable declaration here
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
//Your code here
}
}
After we have created the new Activity, we have to register it in file ‘AndroidManifest.xml’.
For registering we have to create an entry in ‘AndroidManifest.xml’ as
<activity android:name=".NextActivity" android:label="@string/app_name"> </activity>
Note that here we have not used intent filter , since we are going to use an explicit intent, the syntax of intent filter is
<intent-filter> <action android:name="<action here>"/> <category android:name="<category here>"/> </intent-filter>
Here,
action — The general action to be performed
category — Gives additional information about the action to execute. For example, CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can perform on a piece of data.
Note: you can also use application tab below the ‘AndroidManifest.xml’ file, and in ‘Application Nodes’ section click
‘Add’ button as shown in figure below and select the activity .

Application Node-Add Activity
Next you can start this activity on any event as follows
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
CurrentActivity.this.startActivity(myIntent);
Here, you have to create and intent with CurrentActivity.this as first parameter
and the the next activity as second parameter.
After you have created the intent, you can start the new activity by calling
startActivity, on current Activity, with the created intent as parameter.
Recent Comments