Joke Collection Website - Blessing messages - Android Lecture 6 Broadcast Receivers and Services
Android Lecture 6 Broadcast Receivers and Services
Dynamic registration:
1) dynamic registration: you need to define a subclass that inherits from the BroadcastReceiver class, and the receiver needs to log off in the active onDestroy.
2) static registration: by configuring in AndroidManifest.xml
There are two forms of broadcasting: orderly broadcasting and disorderly broadcasting.
1) Out-of-order broadcast: The receiver receiving the standard broadcast will receive the broadcast message at the same time, which will be executed asynchronously instead of sending the broadcast in sequence.
2) Ordered broadcast: SendOrdered broadcast is accepted in a certain order, which is determined by the priority attribute. The broadcast interrupted the broadcast.
If you only want to send and receive broadcasts in this application, use LocalBroadcastReceiver to manage broadcasts.
Local broadcasting does not support static registration.
Advantages: safe and efficient.
Service is a component in Android, which is consistent with the activity level, but it can't run by itself, only in the background, interacting with other components, and the service must be registered before it can be used.
Local service: This service is attached to the main thread, saving resources. When the main thread dies, the service will also be terminated.
Remote service: the service is in an independent process, with good flexibility and high resource occupation.
Start modes of two services:
1) startup mode: the caller is not associated with the service, and the caller's exit will not affect the service. StartService starts the service. If the service does not exist, call the onCreat method, and then call onStartCommand. StopService closes the service and calls the onDestroy method.
2) binding mode: the caller binds to the service, the caller exits, the service terminates, the bindService starts the service, the onCreate method creates the service, the onBind method binds the service, the onbind method unbinds, and the onDestory is called at the end of the service.
- Previous article:Shopping on Taobao with WeChat, where will the SMS be sent?
- Next article:Where can I find cloud backup?
- Related articles
- Factual arguments about will
- When will the Shanghai epidemic end and return to normal in 2022? The latest news of lifting the ban in Shanghai.
- A collection of simple and warm weekend greetings and classics 2017
- My husband and I have a bad relationship, but how can I comfort him when something happens to him?
- Does it take three months to inform the owner of speeding on the expressway?
- When will Shen Shuo, who has the same academic ability in May, check the results?
- Do low-risk areas in Dongguan need to be isolated when returning to Shanwei?
- What is the psychology of people who don't reply to information for a long time?
- Will the water in the water tank of Wuling Light 6376C enter the air or be discharged directly? Or add water while putting water! Ask a friend for advice! thank you
- Xiaoxiang Youpin mobile phone is in stock, will there be a return call?