8-25 Android Learning Notes

Source: Internet
Author: User

1.Intent activating a new activity

Activating the component, accompanying the data

Set the component to be activated explicit intent

1>intent.setclass (this,otheractivity.class)

2>Intent.setclassname (This, "PackageName. Otheractivity ")

3>intent.setcomponent (New ComponentName (This,otheractivity.class))

4>intent Intent = new Intent (this,otheractivity.class)

Pass parameters between two activity

1>intent transfer parameters, new Activity getintent ()

2>bundle Object passing Parameters

2.activity Start-up mode Launchmode

1>standard

This is the default mode, each time the activity is activated, an activity instance is created each time and placed in the task stack

2>singletop

If there is an instance of the activity at the top of the task, the instance is reused (called the instance's Onnewintent ()), otherwise a new instance is created and placed on top of the stack (PS: an instance of the activity exists in a timely stack, as long as it is not on top of the stack, an instance is created)

3>singletask

If an instance of the activity is already in the stack, the instance is reused (Onnewintent () of the instance is invoked). When reused, the instance is returned to the top of the stack, so instances above it will be moved out of the stack. If the instance does not exist in the stack, a new instance is created and placed in the stack

4>singleinstance

Create an instance of the activity in a new stack, and have multiple apps share the activity instances in the stack. Once an instance of the activity of the pattern already exists in a stack, any reactivation of the activity will reuse the instance in that stack (which invokes the instance's Onnewintent ()), the effect of which is equivalent to sharing an application with multiple applications. Whoever activates the activity will go into the same app.

3.Intent

Android's basic design philosophy is to encourage the reduction of coupling between components, so Android provides intent (intent), intent provides a generic messaging system that allows you to pass intent between your application and other applications to perform actions and generate events. Use intent to activate Android apps three types of core components: events, services, and broadcast receivers

Intent can be divided into explicit and implicit intents

Explicit intent: Calling the Intent.setcomponent () or intent.setclassname () or Intent.serclass () method specifies the intent of the component name as an explicit intent, Explicit intent explicitly specifies which component of the component to activate

Implicit intent: Intent with no explicitly specified component name is implicitly intended. The Android system finds the most appropriate component to handle this intent based on the Action category (category) data (URL and data type) set in the implicit intent. The lookup rules are as follows:

<intent-filter>

<action android:name= "Android.intent.action.CALL"/>

<category android:name= "Android.intent.category.DEFAULT"/>

<data android:scheme= "Tel"/>

</intent-filter>

<intent-filter>

<action android:name= "Android.intent.action.CALL"/>

<category android:name= "Android.intent.category.DEFAULT"/>

<data android:mimetype= "Vnd.android.cursor.item/phone"/>

</intent-filter>

Life cycle of 4.Activity

There are three states of activity

When activity is in the foreground of the screen (at the top of the current task stack), it is active or running and can respond to user actions

When there is another activity on top of the acitvity, the activity above does not completely cover it, or the activity above is transparent, the activity below is visible to the user, and the lower one remains paused. This activity is killed if the system is running out of memory

When activity is completely overwritten by another activity, all state and member information remains, but the user is not visible, its window is completely hidden, and if memory is needed elsewhere, the system kills the activity

When activity transitions from one state to another, the following protection methods are called to notify this change:

void OnCreate (Bundle savedinstancestate)

void OnStart ()

void Onrestart ()

void Onresume ()

void OnPause ()

void OnStop ()

void OnDestroy ()

8-25 Android Learning Notes

Related Article

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.