Now the application supports the Fragment API via the Compatibility Libraries. All UI event handling and business logic defined in the different activities was moved to the corresponding fragments (e.g. ContactsActivity --> ContactsListFragment). I also added a few extra lines in Activity's onCreate() to make sure that the Intent extras passed to the Activity are easily accessible from the Fragment as arguments:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
ContactsListFragment fragment = new ContactsListFragment();
Bundle arguments = getIntent().getExtras();
fragment.setArguments(arguments == null ? new Bundle() : arguments);
getSupportFragmentManager().beginTransaction().add(
android.R.id.content, fragment).commit();
}
}
So adding fragment support was pretty straightforward, and no new UI elements have been added. The aim was to make the application easier to port for Android 3.0+.
No comments:
Post a Comment