Android Four components

Source: Internet
Author: User

one of the four components: Activity

activity life cycle: Create-to-run (visible actionable): onCreate () OnStart () Onresume ( )

Run-to-destroy (off): OnPause () onStop () OnDestroy ()

Run-stop (invisible and not operable): OnPause () onStop ()

Stop--run Onrestart () OnStart () Onresume ()

Run-to-pause (visible not operable) OnPause ()

Pause-to-run Onresume ()

1.activity creates three main elements: a: Declaring a class inheriting activity B: Associating layout C: Declaring package name in manifest, class name

Jump between 2.Activity (intention): startactivity (Intent);

3.A receives the message returned by the B interface and processes it: the Onactivityresult () method must be rewritten upon receipt (judging the returned content based on the request code and the result code)

4. Button click event: OnClick = "BTN"

In layout: public void btn (View v) {}

two of the four components:

Service Services

1. Service Open: StartService (); Service closed: StopService

2. Binding and unbinding of services: Bindservice (); Unbindservicce ();

Three of the four components:

Broadcastrecevice Broadcast recipient

1. There are two ways to register a broadcast receiver: A: List registration B: Code registration

Difference: A broadcasts can be received regardless of whether the application executes as long as the conditions are met, and B can be received only when the app is running and the conditions are the same.

Filter conditions:

Checklist: Permissions: Receive_sms condition: <cation ... "Android.provider.Telephony.SMS_RECEIVED"/>

Code: Permissions: receive_sms Condition: registerreceiver (Receiver,filter);

Receiver for matching broadcast

Filter for filtering conditions

When you register a broadcast using code, you must unregisterreceiver

Four components:

Content Provider Contents Provider



Android Four components

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.