Android Fragment Learning

Source: Internet
Author: User

Yesterday wrote an article on the use of fragment optimization techniques, one is to reduce the re-assignment of member variables, the second is to use Hide (), show () and other methods to replace replace (), so that the fragment does not need to be created more than once, but this also brings another problem, This is what I did not consider yesterday, that is the use of memory, only hidden and not destroyed, in the use of memory is not reasonable, some small projects may not see any problem, but once in large projects to do so, may cause memory shortage, so how to use to see how you choose. In addition, I have to correct a mistake yesterday, that is, replace () will cause time-consuming operation, so it is not accurate, time-consuming is mainly due to the initialization time of the fragment, today I use a blank fragment to switch, found that did not cause time-consuming, which knocked over my conclusion yesterday, Viewed again from the life cycle of the fragment, it is found that the Oncreatview call is not called directly after the Onresume, but also requires a method that calls its other life cycles, including the activity's OnStart and onresum, so The time-consuming operation should be caused by some code execution inside Android, which is limited, so there is no need to drill down to the bottom, just note that when we encounter a clip, there are two optimization methods, one is the cache fragment, the other is the time to shorten the initialization.


Well, the other is yesterday said Fragmenttabhost by the line fragment switch, yesterday just said not to see the source, today I was under the guidance of the teacher to find the source code, and thus also learned that the fragment in the fragmenttabhost inside the switch mode, first on the source path, you may know, It is

Sdk\extras\android\support\v4\src\java\android\support\v4\app. This path you can find V4 package of source code, convenient for us to learn. Of course, others like V7 package can also be found, open source is good. As for this kind of how to carry out fragment management, because it is only coarse-looking, not good to take out to say, wait for the next. Because there is nothing to write the experience of the blog, the preparation is not very full, the code is not posted out, so that people look rather difficult, can only say the sound sorry, and strive to improve in the future.




Android Fragment Learning

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.