從Android 3.0(API11) 起,Google 支援Fragment。今天稍微說說什麼是Fragment (https://developer.android.com/guide/fragments)。
A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment. The fragment’s view hierarchy becomes part of, or attaches to, the host’s view hierarchy.
依Google Android Development 的介紹,Fragment 可以有以下的特點:
簡單看Fragment,它就是「模組化」的使用者介面,只是它可以依不同的情況使用而有不同的生命週期。
一個Activity 可以包含多個Fragment
Fragment 的生命週期可以包含有(https://developer.android.com/guide/fragments/lifecycle):
INITIALIZED: onCreate(), onCreateView(), onViewcreated()
CREATED: onViewStateRestored(); onStop(), onSaveInstanceState(), onDestroyView()
STARTED: onStart(); onPause()
RESUMED: onResume()
DESTROYED: onDestroy()