Thoughts on automatically adding placeholderfragment to the new SDK

Source: Internet
Author: User

Since the android SDK was updated to 22.6.3, a fragment is automatically generated when an activity is created. This fragment is a static internal class of the activity, and an XML file named fragment_main.xml is generated. Open activity_main.xml and find that there is only one container left. Obviously, Google wants everyone to write the UI in fragment.

After fragment came out, I discussed it with my friends, saying that Google has caused a mess. An app can be implemented only by activity, that is, an app is composed of multiple activities. There can also be only one activity, which is implemented by multiple fragment, or by mixing multiple activities and multiple fragment. No one gives the answer to the question. I don't know if my information is poor. What new features did Google provide? Why? What are the advantages and disadvantages? Google does not provide any answer either.

Now this new SDK is the answer given by Google with actual actions. That is to say, we hope people can use fragment and activity more. However, there is still a lack of guidance such as best practices for such a change. For example, there is no guidance for jump between fragment, replace or show/hide. Everyone is very busy now. If someone can give the best practice, they don't need to explore it on their own, because the results will be the same as they would if they tried to find something better. So if someone can give the best practices, it will obviously save a lot of time. Google is the most suitable person for doing this job. Why should we add this? It is obviously Google's first thought. They should think about the advantages and disadvantages thoroughly,. Publishing their ideas is undoubtedly the most direct and thorough best practice. I have not found the instruction document officially released by Google. It may be that I am not well informed. If someone knows that Google is doing this, please let me know.

However, because of the historical burden, Google has not completely changed. For example, although a placeholderfragment is generated, the interface should be written in fragment, but in XML, the simple method Android: onclick is called in acitvity. If an activity is used for multiple fragment statements, this simple method is almost useless. This placeholderfragment does not have any practical use. It symbolizes being greater than reality. It must be independent, and fragment does not need to be made into an internal class.

If you are used to using activity to handle things, it is displayed that you are not satisfied with the SDK's self-made ideas to generate fragment. Therefore, many people on the Internet directly Delete the fragment. If you do not delete an activity, an additional file will be added for no reason, resulting in too many files in the project.

If you are bored, it only means that everyone is embracing change. When fragment came out, he wanted to solve the problem of mobile phone and tablet adaptation. But the results are obviously not satisfactory. In my personal experience, I would rather enlarge the version of the mobile phone running on the tablet. Automatic Adaptation is indeed too difficult.

Fragment is considered a reusable component with logic, but it is more suitable. I think this is the biggest use of fragment. In terms of the interface, fragment and view are no different, but the view code and view are not a whole, while the fragment is a whole, no matter which activity is embedded, all functions can be independently executed.

In this way, we need to think more carefully at the beginning of the design than the activity.


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.