How many ways of transferring data between Android pages? What are the advantages?

Source: Internet
Author: User
  1. If there is a direct relationship between the pages, such as activity and the fragment within it, you can pass the data directly through the invocation of the interface. Advantages: direct, convenient. Disadvantage: High Code coupling

  2. If it is two activity between the data transfer, there is the process of interface switching, you can use StartActivity
    or Startactivityforresult. Carry the data with the intent parameter. Advantage: Typically used to initialize activity and invoke system functions

  3. If you pass data between pages without the process of page switching, you can broadcast the way, sendbroadcast (intent);
    The page to accept the data is registered for the broadcast.

Advantages: Code coupling is low, easy to refactor, wide range of applications. Cons: Data needs to be serialized and deserialized, with more code

4. Share data via storage media, such as page A to store data in a database, sharedpreferences
, file, Internet. Page b obtains data by reading them

Advantages: Long data retention, unaffected by the interface life cycle disadvantages: Slow read speed, asynchronous operation required

5. The event bus is used to register and receive events (data), where the Representative is Eventbus, and the page needs to specify and register the type of event received

Advantages: No serialization of data, the scope of application of a large disadvantage: need to learn to use,

How many ways of transferring data between Android pages? What are the advantages?

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.