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?