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
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
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?