Android Internship notes (3)---Fragment with app package or V4 package parsing

Source: Internet
Author: User

Android Internship notes (3)---Fragment with app package or V4 package parsing



1) Problem brief

Believe that a lot of friends in the call fragment will encounter the following situation:


This time the problem comes ...

In the end is to use Android.app under the fragment or Android.support.v4.app bag under the fragment?



Answer: Actually all can, yes, can all!!! We all know that fragment was introduced after 3.0 (API 11).

So what if the app needs to run in a version under 3.0? For example, there is a little bit of market share of 2.3!

As a V4, the package has comeinto being, and the minimum is compatible to version 1.6!

As to which package to use to see your needs, now 3.0 of the mobile phone market share is actually not much, along the street are

More than 4.0, so this time, you can directly use the app package under the fragment, and then call the relevant method

usually there is no problem; If you fragment use the app pack, Fragmentmanager and Fragmenttransaction

It needs to be an app package.


Either use all the app, or all with V4, otherwise it will be an error Oh!

Of course if you want your app to be compatible with the lower version of the phone, then you can choose to use the V4 package

But use V4 pack a lot to pay attention to place!



2) Things to note when using the V4 package:


① If you use the fragment under the V4 package, then the activity will inherit fragmentactivity Oh!

Case: The fragment is loaded statically in the XML file today, and then the fragment is rewritten, but when the activity is loaded, an error is made.

Probably the hint is fragment error or can not find what, the Name property changed several times or wrong! I finally found out it was used.

V4 of the bag, just let your own activity to change to fragmentactivity can!



② write this code today when it is not used, the error situation is as follows:


A little baffling ah, fragment,fragmentmanager,fragmenttransaction are used V4 bag Ah,

Activity is also inherited fragmentactivity ah? Change to the app bag, but it's not with US V4 bag.

Does the premise conflict? There is a solution, huh?

A: Just change the Getfragmentmanager () to Getsupportfragmentmanager ().

Android Internship notes (3)---Fragment with app package or V4 package parsing

Related Article

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.