1. Create an activity
2. Configure the AndroidManifest. xml file
<Application ..
<Activity android: name = ". NewActivity"
Android: label = ".."
Android: launchMode = "standard/singleTop/singleTask/singleInstance">
<Intent-filter>
<! -- Program entry -->
<Action android: name = "android. intent. action. MAIN"/>
<! -- Whether it appears on the startup page -->
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>
</Application>
LaunchMode:
Standard: each time a new activity window is started (new Operation)
SingleTop: if it is a target activity at the top of the stack, It will be opened directly. Otherwise, a new activity window (new) will be opened ).
SingleTask and singleInstance are basically the same. The difference is that if the root activity is set to singleTask
The started activity is also in the same task. If the root activity is set to singleInstance, the enabled activity is in the new task. That is
There is only one activity in the stack. The rest is the same.
2. Configure the AndroidManifest. xml file
<Application ..
<Activity android: name = ". NewActivity"
Android: label = ".."
Android: configChanges = "mcc | mnc"
Android: launchMode = "standard/singleTop/singleTask/singleInstance"/>
</Application>
Android: configChanges:
When the specified attribute (Configuration Changes) Changes, the notification program calls
OnConfigurationChanged () function.
3. Declare Activity permissions (only components with specified permissions can be called)
<Activity android: permission = "cn. itcast. permission. secondwindow"/>
<Cycler android: permission = "cn. itcast. permission. secondwindow"/>
4. Define and use Permissions
<Permission android: name = "cn. itcast. permission. secondwindow"/>
<Uses-permission android: name = "cn. itcast. permission. secondwindow"/>
1. Create an activity
XxxActivity extends Activity {...}
2. Configure the AndroidManifest. xml file
<Application ..
<Activity android: name = ". NewActivity" android: label = ".."
Android: launchMode = "standard/singleTop/singleTask/singleInstance"/>
</Application>
3. Open a new activity (no return value is required)
// Display
StartActivity (new Intent (context, XxxActivity. class ));
// PASS Parameters to intent
Bundle = new Bundle ();
Bundle. setString (...);
Intent. putExtra (bundle );
4. Accept parameters in Intent
Conext. getIntent (). getBundle (). getString (..)
5. Evaluate the bundle class
3. Start the activity for the result (startActivityForResult)
// 1: Request Code
StartActivityForResult (new Intent (...), 1 );
4. process the returned results
XxxActivity extends Activity {
...
// Call back this method after the activity ends.
Protected void onActivityResult (int reqCode, int resCode, Intent data ){
String result = data. getExtras (). getString ("result "));
}
...
}
5. Set returned results of intent
Intent intent = new Intent ();
Intent. putExtra (...); www.2cto.com
Context. setResult (RESULT_ OK, intent );
Context. finish ();
Author: to1297488504