public class FragmentActivity extends Activity
Fragment
and
Loader
APIs.
When using this class as opposed to new platform's built-in fragment
and loader support, you must use the getSupportFragmentManager()
and getSupportLoaderManager()
methods respectively to access
those features.
Known limitations:
When using the <fragment> tag, this implementation can not use the parent view's ID as the new fragment's ID. You must explicitly specify an ID (or tag) in the <fragment>.
Prior to Honeycomb (3.0), an activity's state was saved before pausing. Fragments are a significant amount of new state, and dynamic enough that one often wants them to change between pausing and stopping. These classes throw an exception if you try to change the fragment state after it has been saved, to avoid accidental loss of UI state. However this is too restrictive prior to Honeycomb, where the state is saved before pausing. To address this, when running on platforms prior to Honeycomb an exception will not be thrown if you change fragments between the state save and the activity being stopped. This means that in some cases if the activity is restored from its last saved state, this may be a snapshot slightly before what the user last saw.
DEFAULT_KEYS_DIALER, DEFAULT_KEYS_DISABLE, DEFAULT_KEYS_SEARCH_GLOBAL, DEFAULT_KEYS_SEARCH_LOCAL, DEFAULT_KEYS_SHORTCUT, FOCUSED_STATE_SET, RESULT_CANCELED, RESULT_FIRST_USER, RESULT_OK
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_VISIBLE, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, COUNTRY_DETECTOR, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_ROUTER_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_POLICY_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, SCHEDULING_POLICY_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SERIAL_SERVICE, SIP_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, THROTTLE_SERVICE, UI_MODE_SERVICE, UPDATE_LOCK_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
FragmentActivity() |
Modifier and Type | Method and Description |
---|---|
void |
dump(String prefix,
FileDescriptor fd,
PrintWriter writer,
String[] args)
Print the Activity's state into the given stream.
|
Object |
getLastCustomNonConfigurationInstance()
Return the value previously returned from
onRetainCustomNonConfigurationInstance() . |
FragmentManager |
getSupportFragmentManager()
Return the FragmentManager for interacting with fragments associated
with this activity.
|
LoaderManager |
getSupportLoaderManager()
Return the LoaderManager for this fragment, creating it if needed.
|
protected void |
onActivityResult(int requestCode,
int resultCode,
Intent data)
Dispatch incoming result to the correct fragment.
|
void |
onAttachFragment(Fragment fragment)
Called when a fragment is attached to the activity.
|
void |
onBackPressed()
Take care of popping the fragment back stack or finishing the activity
as appropriate.
|
void |
onConfigurationChanged(Configuration newConfig)
Dispatch configuration change to all fragments.
|
protected void |
onCreate(Bundle savedInstanceState)
Perform initialization of all fragments and loaders.
|
boolean |
onCreatePanelMenu(int featureId,
Menu menu)
Dispatch to Fragment.onCreateOptionsMenu().
|
View |
onCreateView(String name,
Context context,
AttributeSet attrs)
Add support for inflating the <fragment> tag.
|
protected void |
onDestroy()
Destroy all fragments and loaders.
|
boolean |
onKeyDown(int keyCode,
KeyEvent event)
Take care of calling onBackPressed() for pre-Eclair platforms.
|
void |
onLowMemory()
Dispatch onLowMemory() to all fragments.
|
boolean |
onMenuItemSelected(int featureId,
MenuItem item)
Dispatch context and options menu to fragments.
|
protected void |
onNewIntent(Intent intent)
Handle onNewIntent() to inform the fragment manager that the
state is not saved.
|
void |
onPanelClosed(int featureId,
Menu menu)
Call onOptionsMenuClosed() on fragments.
|
protected void |
onPause()
Dispatch onPause() to fragments.
|
protected void |
onPostResume()
Dispatch onResume() to fragments.
|
boolean |
onPreparePanel(int featureId,
View view,
Menu menu)
Dispatch onPrepareOptionsMenu() to fragments.
|
protected void |
onResume()
Dispatch onResume() to fragments.
|
protected void |
onResumeFragments()
This is the fragment-orientated version of
onResume() that you
can override to perform operations in the Activity at the same point
where its fragments are resumed. |
Object |
onRetainCustomNonConfigurationInstance()
Use this instead of
onRetainNonConfigurationInstance() . |
Object |
onRetainNonConfigurationInstance()
Retain all appropriate fragment and loader state.
|
protected void |
onSaveInstanceState(Bundle outState)
Save all appropriate fragment state.
|
protected void |
onStart()
Dispatch onStart() to all fragments.
|
protected void |
onStop()
Dispatch onStop() to all fragments.
|
void |
startActivityForResult(Intent intent,
int requestCode)
Modifies the standard behavior to allow results to be delivered to fragments.
|
void |
startActivityFromFragment(Fragment fragment,
Intent intent,
int requestCode)
Called by Fragment.startActivityForResult() to implement its behavior.
|
void |
supportInvalidateOptionsMenu()
Invalidate the activity's options menu.
|
addContentView, closeContextMenu, closeOptionsMenu, createPendingResult, dismissDialog, dispatchGenericMotionEvent, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, findViewById, finish, finishActivity, finishActivityFromChild, finishAffinity, finishFromChild, getActionBar, getActivityToken, getApplication, getCallingActivity, getCallingPackage, getChangingConfigurations, getComponentName, getCurrentFocus, getFragmentManager, getIntent, getLastNonConfigurationInstance, getLayoutInflater, getLoaderManager, getLocalClassName, getMenuInflater, getParent, getParentActivityIntent, getPreferences, getRequestedOrientation, getSystemService, getTaskId, getTitle, getTitleColor, getVolumeControlStream, getWindow, getWindowManager, hasWindowFocus, invalidateOptionsMenu, isChangingConfigurations, isChild, isDestroyed, isFinishing, isImmersive, isResumed, isTaskRoot, managedQuery, managedQuery, moveTaskToBack, navigateUpTo, navigateUpToFromChild, onActionModeFinished, onActionModeStarted, onApplyThemeResource, onAttachedToWindow, onAttachFragment, onChildTitleChanged, onContentChanged, onContextItemSelected, onContextMenuClosed, onCreateContextMenu, onCreateDescription, onCreateDialog, onCreateDialog, onCreateNavigateUpTaskStack, onCreateOptionsMenu, onCreatePanelView, onCreateThumbnail, onCreateView, onDetachedFromWindow, onGenericMotionEvent, onKeyLongPress, onKeyMultiple, onKeyShortcut, onKeyUp, onMenuOpened, onNavigateUp, onNavigateUpFromChild, onOptionsItemSelected, onOptionsMenuClosed, onPostCreate, onPrepareDialog, onPrepareDialog, onPrepareNavigateUpTaskStack, onPrepareOptionsMenu, onRestart, onRestoreInstanceState, onSearchRequested, onTitleChanged, onTouchEvent, onTrackballEvent, onTrimMemory, onUserInteraction, onUserLeaveHint, onWindowAttributesChanged, onWindowFocusChanged, onWindowStartingActionMode, openContextMenu, openOptionsMenu, overridePendingTransition, recreate, registerForContextMenu, removeDialog, requestWindowFeature, runOnUiThread, setContentView, setContentView, setContentView, setDefaultKeyMode, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setFinishOnTouchOutside, setImmersive, setIntent, setPersistent, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRequestedOrientation, setResult, setResult, setSecondaryProgress, setTitle, setTitle, setTitleColor, setVisible, setVolumeControlStream, shouldUpRecreateTask, showDialog, showDialog, startActionMode, startActivities, startActivities, startActivity, startActivity, startActivityAsUser, startActivityAsUser, startActivityForResult, startActivityFromChild, startActivityFromChild, startActivityFromFragment, startActivityFromFragment, startActivityIfNeeded, startActivityIfNeeded, startIntentSender, startIntentSender, startIntentSenderForResult, startIntentSenderForResult, startIntentSenderFromChild, startIntentSenderFromChild, startManagingCursor, startNextMatchingActivity, startNextMatchingActivity, startSearch, stopManagingCursor, takeKeyEvents, triggerSearch, unregisterForContextMenu
applyOverrideConfiguration, attachBaseContext, getResources, getTheme, getThemeResId, setTheme
bindService, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createDisplayContext, createPackageContext, createPackageContextAsUser, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getCompatibilityInfo, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalFilesDir, getFilesDir, getFileStreamPath, getMainLooper, getObbDir, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getSharedPreferences, getSharedPrefsFile, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiverAsUser, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setWallpaper, setWallpaper, startActivitiesAsUser, startInstrumentation, startService, startServiceAsUser, stopService, stopServiceAsUser, unbindService, unregisterReceiver
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
protected void onActivityResult(int requestCode, int resultCode, Intent data)
onActivityResult
in class Activity
requestCode
- The integer request code originally supplied to
startActivityForResult(), allowing you to identify who this
result came from.resultCode
- The integer result code returned by the child activity
through its setResult().data
- An Intent, which can return result data to the caller
(various data can be attached to Intent "extras").Activity.startActivityForResult(android.content.Intent, int)
,
Activity.createPendingResult(int, android.content.Intent, int)
,
Activity.setResult(int)
public void onBackPressed()
onBackPressed
in class Activity
public void onConfigurationChanged(Configuration newConfig)
onConfigurationChanged
in interface ComponentCallbacks
onConfigurationChanged
in class Activity
newConfig
- The new device configuration.protected void onCreate(Bundle savedInstanceState)
onCreate
in class Activity
savedInstanceState
- If the activity is being re-initialized after
previously being shut down then this Bundle contains the data it most
recently supplied in Activity.onSaveInstanceState(android.os.Bundle)
. Note: Otherwise it is null.Activity.onStart()
,
Activity.onSaveInstanceState(android.os.Bundle)
,
Activity.onRestoreInstanceState(android.os.Bundle)
,
Activity.onPostCreate(android.os.Bundle)
public boolean onCreatePanelMenu(int featureId, Menu menu)
onCreatePanelMenu
in interface Window.Callback
onCreatePanelMenu
in class Activity
featureId
- The panel being created.menu
- The menu inside the panel.public View onCreateView(String name, Context context, AttributeSet attrs)
onCreateView
in interface LayoutInflater.Factory
onCreateView
in class Activity
name
- Tag name to be inflated.context
- The context the view is being created in.attrs
- Inflation attributes as specified in XML file.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet)
,
Window.getLayoutInflater()
protected void onDestroy()
onDestroy
in class Activity
Activity.onPause()
,
Activity.onStop()
,
Activity.finish()
,
Activity.isFinishing()
public boolean onKeyDown(int keyCode, KeyEvent event)
onKeyDown
in interface KeyEvent.Callback
onKeyDown
in class Activity
keyCode
- The value in event.getKeyCode().event
- Description of the key event.true
to prevent this event from being propagated
further, or false
to indicate that you have not handled
this event and it should continue to be propagated.Activity.onKeyUp(int, android.view.KeyEvent)
,
KeyEvent
public void onLowMemory()
onLowMemory
in interface ComponentCallbacks
onLowMemory
in class Activity
public boolean onMenuItemSelected(int featureId, MenuItem item)
onMenuItemSelected
in interface Window.Callback
onMenuItemSelected
in class Activity
featureId
- The panel that the menu is in.item
- The menu item that was selected.public void onPanelClosed(int featureId, Menu menu)
onPanelClosed
in interface Window.Callback
onPanelClosed
in class Activity
featureId
- The panel that is being displayed.menu
- If onCreatePanelView() returned null, this is the Menu
being displayed in the panel.protected void onPause()
onPause
in class Activity
Activity.onResume()
,
Activity.onSaveInstanceState(android.os.Bundle)
,
Activity.onStop()
protected void onNewIntent(Intent intent)
onNewIntent
in class Activity
intent
- The new intent that was started for the activity.Activity.getIntent()
,
Activity.setIntent(android.content.Intent)
,
Activity.onResume()
protected void onResume()
onResumeFragments()
.onResume
in class Activity
Activity.onRestoreInstanceState(android.os.Bundle)
,
Activity.onRestart()
,
Activity.onPostResume()
,
Activity.onPause()
protected void onPostResume()
onPostResume
in class Activity
Activity.onResume()
protected void onResumeFragments()
onResume()
that you
can override to perform operations in the Activity at the same point
where its fragments are resumed. Be sure to always call through to
the super-class.public boolean onPreparePanel(int featureId, View view, Menu menu)
onPreparePanel
in interface Window.Callback
onPreparePanel
in class Activity
featureId
- The panel that is being displayed.view
- The View that was returned by onCreatePanelView().menu
- If onCreatePanelView() returned null, this is the Menu
being displayed in the panel.Window.Callback.onCreatePanelView(int)
public final Object onRetainNonConfigurationInstance()
onRetainCustomNonConfigurationInstance()
if you want to retain your own state.onRetainNonConfigurationInstance
in class Activity
protected void onSaveInstanceState(Bundle outState)
onSaveInstanceState
in class Activity
outState
- Bundle in which to place your saved state.Activity.onCreate(android.os.Bundle)
,
Activity.onRestoreInstanceState(android.os.Bundle)
,
Activity.onPause()
protected void onStart()
onStart
in class Activity
Activity.onCreate(android.os.Bundle)
,
Activity.onStop()
,
Activity.onResume()
protected void onStop()
onStop
in class Activity
Activity.onRestart()
,
Activity.onResume()
,
Activity.onSaveInstanceState(android.os.Bundle)
,
Activity.onDestroy()
public Object onRetainCustomNonConfigurationInstance()
onRetainNonConfigurationInstance()
.
Retrieve later with getLastCustomNonConfigurationInstance()
.public Object getLastCustomNonConfigurationInstance()
onRetainCustomNonConfigurationInstance()
.public void supportInvalidateOptionsMenu()
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
dump
in class Activity
prefix
- Desired prefix to prepend at each line of output.fd
- The raw file descriptor that the dump is being sent to.writer
- The PrintWriter to which you should dump your state. This will be
closed for you after you return.args
- additional arguments to the dump request.public void onAttachFragment(Fragment fragment)
public FragmentManager getSupportFragmentManager()
public void startActivityForResult(Intent intent, int requestCode)
startActivityForResult
in class Activity
intent
- The intent to start.requestCode
- If >= 0, this code will be returned in
onActivityResult() when the activity exits.Activity.startActivity(android.content.Intent)
public void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode)
public LoaderManager getSupportLoaderManager()