Android Radio and services

Source: Internet
Author: User

One, broadcast 2 different ways of registering the choice:

Andorid broadcasts have manual registration and manifest file registration in 2 ways:

  1. Manifest file registration, no need to do anything in the code, or even instantiate the broadcast receiver. Because Android will create an instance and manage its life cycle. Note that the instance that receives the OnReceive () call is valid only for the duration of OnReceive (). In fact, Each call to the OnReceive () method is likely to occur on a different broadcast receive instance. This means that you must avoid calling other classes asynchronously.
  2. Manual registration, you must log off the broadcast when not in use, and if the logoff failure in an activity causes an exception, Andorid will issue a warning of a content leak. This is one of the main differences between 2 different registrations, when manually registering, the application is responsible for the lifetime of the broadcast receiver, while the manifest file is registered, Android handles the life cycle.
Second, broadcast versus service comparison: Broadcast receivers are a lightweight application component that passively collects data compared to services. A broadcast receiver based on manifest registration does not need to exist outside of OnReceive (). So it can be garbage collected immediately after the method returns. The disadvantage of a broadcast receiver is that it does not maintain state between individual onreceive (). Once the OnReceive () method returns, the instance is garbage collected. May cause the instance data to not be saved, thus affecting the next onreceive () call, may be an insurmountable problem,

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.