How to start another activity in the Android app
Activity in the Android application which gave more than one, how to switch the activity?
I think if you want to create an Android app, and it may have let more than one (activity) screen, like that, you want to switch, depending on the operation.
The Android app, how to add an Activity has been covered before, so, please refer to.
How to Add Activity in Eclipse
We will show you how to launch another activity.
As in the case that we introduced earlier to launch, the browser and outbound voice, use the (intent) Intent.
I would like to introduce two ways, and how to start another Activity.
One is when the return value is unnecessary, and one when you need a return value from Activity Activity was launched from the start.
If you do not need the return value from the Activity was started
For example, if you want to start the Activity class name that you created in xxxx, only the following code.
Intent i = new Intent (getApplicationContext (), xxxx.class);
startActivity (i);
Like when you start the browser, will generate an Intent instance, the constructor to pass Intent are different.
If you want to launch the Android Activity in the same application, the first argument is the second argument, set the class name of the Activity to launch, the object type that you obtained in Context () getApplicationContext.
It has an indication that, from within the app finds it for his own, the Activity to be started.
If you require a return value from the Activity was started
Also, in turn, how to start so we can get the return value will be as follows, the Activity class name that you created in xxxx.
Intent i = new Intent (getApplicationContext (), xxxx.class);
startActivityForResult (i, 0);
The difference with the previous example, only that they are using the () startActivityForResult the second row.
Second argument is called the request code.
And is referred to as whether to use for what, sides Activity is started up, if you receive the return value is a code that identifies the return value or in any startup.
It is difficult to put into words and a little.
Looking at the place that receives the return value, you'll see.
Receipt of the return value can be obtained in the following events.
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
}
You have implemented in the class of the caller of the Activity, onActivityResult of the above ().
Then, after calling Activity is finished, the events described above will occur when you come back.
RequestCode of the first argument to this, it came in request code passed in the () startActivityForResult, so you can distribute the processing.
(If you request code was not intended, skip the processing, etc.)
Leave the description of the Activity of the called side, who also returns the return value.
Do the following.
i = new Intent ();
setResult (RESULT_OK, i);
finish ();
the first argument () return value will be setResult.
For example, if you really want to tell you that if you want RESULT_OK tell you that the operation was successful, the process has been canceled, specify the RESULT_CANCELED.
This is a constant that is declared in the Activity class.
Since there is no problem if the type int, if you need the return value of various patterns, the return value will also say that you have defined.
The Intent of the second argument, if there is other information you want to pass to, you can also go and put together.
() is used, if you put that passing the key and value i.putExtra, can be retrieved from the caller.
() description, has written to the following articles putExtra.
How to pass a value to the Activity in Android, to launch
This time is greater than or equal to.












Introduced a way to start the activity of another [...] id app. Not only from side to launch the only way to launch another activity in the Android app to launch, some information [...]