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