Deep understanding of data transfer between activity _android

Source: Internet
Author: User

There is no way to transfer data directly between the activity. Android's design principle is to use intent to communicate between different activity and process, but generally, intent can only be stored in basic data types and system default support such as URIs. So for users to define their own data structure is not directly with the intent to transmit, if you want to pass the intent of custom data, you can make the data structure to implement Parcelable interface, so you can put data into intent. But intent transmission efficiency is not very high, especially when passing some large data such as bitmap, once encountered, with intent pass over 500K of bitmap, will cause the framework layer of the Java Binder Hang, the result is not successful delivery.

This can be counted as one of the drawbacks of Android, there is no good solution. What you can do is try to design as much as possible, and try to share basic data types between the activity.

Android itself is also suffering from the application, you can see a lot of applications in the source code of the main class in more than 3,000 lines, such as browser in the browseractivity has more than 4,000 lines Composemessageactivity also has more than 4,000 lines in MMS. Wait a minute. Why a class can be so large is because they are the main page of the program, the core logic of the business, which controls a lot of other data structures, and cannot be shared with other activities, so you can only do things in one activity.

In addition, although not a good solution, but also acceptable, that is, some data and logic classes in a single key mode, so that each package of classes (including activity) can be accessed, such as the MMS in the data packet inside the workingmessage,conversation, Contact and ContactList are all single bonds.

Hope that the future SDK can have a better solution.

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.