Android Fragment and how it relate to the fragmentation

1:15 AM



After my first application which was developed for version 2.x i decided that it is a good time to get know  better an android API versions 4.x. So i decided to develop some program in order to take a trip for a most interesting and core features in android 4.x.

This is led me to the Fragments. Actually fragments were introduces in Honeycomb (ver 3.0 and higher), but i haven't encountered with them than. Anyhow i felt that it is a good opportunity to know them "from the close distance" :) 

It took me some time to understand what does fragmentation means. I read regarding fragment and its life cycle and it looks like it would take a couple of minutes to implement some fragments into my app. But there was a surprise :)

Apparently there were two implementation of Fragments. First one was related to android version below v 3.0 and the second one was for versions higher then android 3.0. At this point i stoping intimidate you and just gonna introduce key differences.

The key differences are:
  • Fragments prior android version 3.0
  • getSupportFragmentManager() to get android.support.v4.app.FragmentManager
  • getSupportLoaderManager() to get android.support.v4.app.LoaderManager
  • Fragments higher then android version 3.0
  • Use Activity instead of FragmentActivity to hold Fragments
  • getFragmentManager() to get android.app.FragmentManager
  • getLoaderManager() to get android.app.LoaderManager

Some tips and advises:
1. Sometimes better to declare implicit everything related to fragments: Fragment, FragmentManager and etc..
2. If you working prior android 3.0, please make sure that you don't have following imports:
import android.app.Fragment;
import android.app.FragmentTransaction;
but you have android.support.v4.app.fragment and such..

P.S.
1.I will update tips and advises constantly :)
2. I always would like to hear your opinion.

You Might Also Like

0 comments.

Popular Posts

Google+ Followers

Total Pageviews