Android four components (i) Activity

Source: Internet
Author: User

First, create a new activity

The four components of 1.android are configured in the manifest file

2. If you want to have multiple launch icons for your app, your activity needs to be configured like this

    <intent-filter>                <action android:name= "Android.intent.action.MAIN"/>                <category android: Name= "Android.intent.category.LAUNCHER"/>            </intent-filter>

The Lable and Icon properties under 3.Activity can be different from the properties of the application node by default with the properties under the application node

Second, intention (intent)

Implicit intent: By specifying a set of actions or data

        New Intent ();         // set the action        of a jump Intent.setaction ("com.cn.testActivity");        Intent.addcategory ("Android.intent.category.DEFAULT");         // Activate activity        StartActivity (Intent);

Explicit: By specifying a specific package name and class name. Intent Intent = new Intent (this,testactivity.class);

Summary: 1. Open your app's interface with display.

2. Open Other applications (System applications) with implicit intent. (Telephone dialer)

3. More secure.

Three, SMS Daquan case
 Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); ListView LV=(ListView) Findviewbyid (r.id.lv); //Setting up dataarrayadapter<string> adapter =NewArrayadapter<string>(Getapplicationcontext (), R.layout.item, R.id.tv_content, objects); //set up data adaptationLv.setadapter (adapter); //set a click event for a ListViewLv.setonitemclicklistener (NewOnitemclicklistener () {@Override Public voidOnitemclick (adapterview<?>Parent, view view,intPositionLongID) {//Take out the data of the clicked itemString content =Objects[position]; Intent Intent=NewIntent (); //Set ActionIntent.setaction ("Android.intent.action.SEND"); Intent.addcategory ("Android.intent.category.DEFAULT"); Intent.settype ("Text/plain"); //Passing DataIntent.putextra ("Sms_body", content); //jump to a page that sends a text messagestartactivity (Intent);    }        }); } }
View CodeIv. life cycle of activity

1.onCreate (): Call OnDestroy () when activity is started: Called when activity is destroyed

2.onRestart ()

3.onStart (): Call OnStop when the activity interface becomes visible (): Called when the activity interface becomes invisible

4.onResume () call OnPause when the interface has a button clicked and gets focus () when the interface button is not clickable and loses focus

Toggle Activity Lifecycle by Screen

android:screenorientation= "Landscape" horizontal screen

android:screenorientation= "Portrait" vertical Screen

Iv. concept of the task stack (related to activity)

1. Stack: Open an activity, out of the stack: close an activity

2. The activity we operate is always the activity at the top of the stack.

The 3.activity task stack is used to maintain the user experience.

4. The task stack is emptied when the application exits.

5. In general, an application corresponds to a task stack.

V. Four startup modes of activity (understanding, follow-up)

1.standard

Application scenario: Bookmarks for browsers

2.singleTop: The activity at the top of the task stack is checked and will not be created if present, and reused directly.

3.singleTask: Check the current task stack,

4.singleInstance: Create a task stack yourself.

Application Scenario: Call page

Android four components (i) Activity

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.