Knowledge about Activity in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.