Android development experience-intent delivering big Data

Source: Internet
Author: User

When you pass information in the activity or component, you generally use the intent binding bundle to pass the value, but in the process of using it, it is important not to pass the bulk data with the bundle:


In the process of doing the project, you need to pass dictation results to the dictation interface for display, but due to the large amount of data sent to the program ANR, or even directly report the exception (the message is bitmap converted into a byte array, each phrase pinyin, words, voice information), After analysis, it is found that the bundle can not pass the large capacity of data information, in the StackOverflow to find peers encountered similar problems:


(1) "Thesize limit of Intent is still pretty low in Jelly beans, which is somewhat lower than 1MB (around 90K) , so all should always be cautious about your data length, even if your application targets only latest Android versions.< /c2> "


(2) "as per my experience (sometime ago), you is able to put1MBof data in aBundleencapsulated insideIntent. I think, this restriction is valid up tillFroyoorGingerbread.”


So when you pass data through bundles with only a small amount of data, there are several alternative ways to solve the problem of not being able to pass the data through bundles when you need to pass bulk data between different components:


Method One: Write the data that needs to be passed in the temporary file or database , and then jump to another component to read the data information, this processing will be due to the time-consuming and read-write files, which makes the program run less efficient;


Method Two: Encapsulate the data information that needs to be passed in a static class (note that the current component and the component to jump to must belong to the same process, because the data can be shared between processes), to set the contents of the class in the current component, and then jump to the component to fetch, this process is highly efficient, But it destroys the independence of the program.


Depending on the specific situation, I suggest to take the second approach, because it will greatly improve the efficiency of the program, as for the independence of the program, see how you encapsulate this class.


Resources:

1, Maximum intent extra size limit

2. Maximum length of Intent PutExtra method?

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.