1.Android Basic Knowledge points

Source: Internet
Author: User

1. What are the four components and their life cycle (and fragment)?

 Activity: Communication via intent, with data on actions and actions in the intent 

Broadcastreceive: You can start an activity or service in the broadcast in response to the received information, or use Notificationmanager to notify the user, you can filter the external data, only to respond to events of interest.

General broadcast: Context.sendboradcast (Intent)

Ordered broadcast: Context.sendorderbroadcast (intent,receiverpermission), Receiverpermission determines the level of broadcasting, the value is between 1000 and 1000, the greater the value, The higher the priority of the send. Received broadcasts can be prioritized by priority in the Intentfilter. Abortbroadcast () can truncate the broadcast.

Asynchronous broadcast: Sent via Context.sendstickybroadcast (intent). There are also sendstickyorderedbroadcast (intent, Resultreceiver, Scheduler, Initialcode, Initialdata, Initialextras) methods, This method has the characteristics of an ordered broadcast and also has the characteristics of asynchronous broadcasting; Send asynchronous broadcast to: <uses-permission android:name="Android.permission.BROADCAST_STICKY" / > permissions, after receiving and processing intent, the broadcast still exists until you call Removestickybroadcast (intent) to remove it.

To listen for broadcast intent: 1. Define a class to inherit Broadcastreceiver, and then override the OnReceive () method.

2. Static registration, registered directly in the manifest file or dynamic registration. Code in Registerreceiver (Receive,intentfilter), logoff Unregisterreceiver (receive).

The broadcast has a life cycle of only 10s, and if it does a time-consuming operation, it can result in ANR.

Service: How to use: 1. Inherit service, register in manifest file. Start with the StartService () or Bindservice () method.

The service started by the StartService () method has no relationship with the caller, even if the caller shuts down and the service is still running to stop the service to call Context.stopservice (), at which point the system calls Ondestory (), when started with this method, The first time the service starts the system calls the service's OnCreate ()-->onstart (), and if the service has started again the call will only trigger the OnStart () method

Services that are started with bindservice () are bound to the caller as long as the caller shuts down the service, and when started using this method, the first time the service starts the system calls the service's OnCreate ()-->onbind (), and if the service has started again, the call will no longer trigger these 2 methods , when the caller exits, the system invokes the service's Onunbind ()-->ondestory (), and the system calls Onunbind ()-->ondestory () in order to actively unbind the binding contex.unbindservice ();

ContentProvider: Other applications can obtain or deposit data from the content provider through the Contentresolver class (see contentprovideraccessapp example)

1.Android Basic Knowledge points

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.