android.support.v4.app
Class FragmentActivity

java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.view.ContextThemeWrapper
              extended by android.app.Activity
                  extended by android.support.v4.app.FragmentActivity
All Implemented Interfaces:
android.content.ComponentCallbacks, android.content.ComponentCallbacks2, android.view.KeyEvent.Callback, android.view.LayoutInflater.Factory, android.view.LayoutInflater.Factory2, android.view.View.OnCreateContextMenuListener, android.view.Window.Callback

public class FragmentActivity
extends android.app.Activity

Base class for activities that want to use the support-based 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:


Field Summary
 
Fields inherited from class android.app.Activity
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
 
Fields inherited from class android.content.Context
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, 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, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, STORAGE_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, UI_MODE_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
Fields inherited from interface android.content.ComponentCallbacks2
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 Summary
FragmentActivity()
           
 
Method Summary
 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, android.content.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(android.content.res.Configuration newConfig)
          Dispatch configuration change to all fragments.
protected  void onCreate(android.os.Bundle savedInstanceState)
          Perform initialization of all fragments and loaders.
 boolean onCreatePanelMenu(int featureId, android.view.Menu menu)
          Dispatch to Fragment.onCreateOptionsMenu().
 android.view.View onCreateView(String name, android.content.Context context, android.util.AttributeSet attrs)
          Add support for inflating the <fragment> tag.
protected  void onDestroy()
          Destroy all fragments and loaders.
 boolean onKeyDown(int keyCode, android.view.KeyEvent event)
          Take care of calling onBackPressed() for pre-Eclair platforms.
 void onLowMemory()
          Dispatch onLowMemory() to all fragments.
 boolean onMenuItemSelected(int featureId, android.view.MenuItem item)
          Dispatch context and options menu to fragments.
protected  void onNewIntent(android.content.Intent intent)
          Handle onNewIntent() to inform the fragment manager that the state is not saved.
 void onPanelClosed(int featureId, android.view.Menu menu)
          Call onOptionsMenuClosed() on fragments.
protected  void onPause()
          Dispatch onPause() to fragments.
protected  void onPostResume()
          Dispatch onResume() to fragments.
 boolean onPreparePanel(int featureId, android.view.View view, android.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(android.os.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(android.content.Intent intent, int requestCode)
          Modifies the standard behavior to allow results to be delivered to fragments.
 void startActivityFromFragment(Fragment fragment, android.content.Intent intent, int requestCode)
          Called by Fragment.startActivityForResult() to implement its behavior.
 void supportInvalidateOptionsMenu()
          Invalidate the activity's options menu.
 
Methods inherited from class android.app.Activity
addContentView, closeContextMenu, closeOptionsMenu, createPendingResult, dismissDialog, dispatchGenericMotionEvent, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, findViewById, finish, finishActivity, finishActivityFromChild, finishAffinity, finishFromChild, getActionBar, 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, isTaskRoot, 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, setIntent, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRequestedOrientation, setResult, setResult, setSecondaryProgress, setTitle, setTitle, setTitleColor, setVisible, setVolumeControlStream, shouldUpRecreateTask, showDialog, showDialog, startActionMode, startActivities, startActivities, startActivity, startActivity, startActivityForResult, startActivityFromChild, startActivityFromChild, startActivityFromFragment, startActivityFromFragment, startActivityIfNeeded, startActivityIfNeeded, startIntentSender, startIntentSender, startIntentSenderForResult, startIntentSenderForResult, startIntentSenderFromChild, startIntentSenderFromChild, startManagingCursor, startNextMatchingActivity, startNextMatchingActivity, startSearch, stopManagingCursor, takeKeyEvents, triggerSearch, unregisterForContextMenu
 
Methods inherited from class android.view.ContextThemeWrapper
applyOverrideConfiguration, attachBaseContext, getResources, getTheme, setTheme
 
Methods inherited from class android.content.ContextWrapper
bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createDisplayContext, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalFilesDir, getFilesDir, getFileStreamPath, getMainLooper, getObbDir, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getSharedPreferences, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setWallpaper, setWallpaper, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
 
Methods inherited from class android.content.Context
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FragmentActivity

public FragmentActivity()
Method Detail

onActivityResult

protected void onActivityResult(int requestCode,
                                int resultCode,
                                android.content.Intent data)
Dispatch incoming result to the correct fragment.

Overrides:
onActivityResult in class android.app.Activity

onBackPressed

public void onBackPressed()
Take care of popping the fragment back stack or finishing the activity as appropriate.

Overrides:
onBackPressed in class android.app.Activity

onConfigurationChanged

public void onConfigurationChanged(android.content.res.Configuration newConfig)
Dispatch configuration change to all fragments.

Specified by:
onConfigurationChanged in interface android.content.ComponentCallbacks
Overrides:
onConfigurationChanged in class android.app.Activity

onCreate

protected void onCreate(android.os.Bundle savedInstanceState)
Perform initialization of all fragments and loaders.

Overrides:
onCreate in class android.app.Activity

onCreatePanelMenu

public boolean onCreatePanelMenu(int featureId,
                                 android.view.Menu menu)
Dispatch to Fragment.onCreateOptionsMenu().

Specified by:
onCreatePanelMenu in interface android.view.Window.Callback
Overrides:
onCreatePanelMenu in class android.app.Activity

onCreateView

public android.view.View onCreateView(String name,
                                      android.content.Context context,
                                      android.util.AttributeSet attrs)
Add support for inflating the <fragment> tag.

Specified by:
onCreateView in interface android.view.LayoutInflater.Factory
Overrides:
onCreateView in class android.app.Activity

onDestroy

protected void onDestroy()
Destroy all fragments and loaders.

Overrides:
onDestroy in class android.app.Activity

onKeyDown

public boolean onKeyDown(int keyCode,
                         android.view.KeyEvent event)
Take care of calling onBackPressed() for pre-Eclair platforms.

Specified by:
onKeyDown in interface android.view.KeyEvent.Callback
Overrides:
onKeyDown in class android.app.Activity

onLowMemory

public void onLowMemory()
Dispatch onLowMemory() to all fragments.

Specified by:
onLowMemory in interface android.content.ComponentCallbacks
Overrides:
onLowMemory in class android.app.Activity

onMenuItemSelected

public boolean onMenuItemSelected(int featureId,
                                  android.view.MenuItem item)
Dispatch context and options menu to fragments.

Specified by:
onMenuItemSelected in interface android.view.Window.Callback
Overrides:
onMenuItemSelected in class android.app.Activity

onPanelClosed

public void onPanelClosed(int featureId,
                          android.view.Menu menu)
Call onOptionsMenuClosed() on fragments.

Specified by:
onPanelClosed in interface android.view.Window.Callback
Overrides:
onPanelClosed in class android.app.Activity

onPause

protected void onPause()
Dispatch onPause() to fragments.

Overrides:
onPause in class android.app.Activity

onNewIntent

protected void onNewIntent(android.content.Intent intent)
Handle onNewIntent() to inform the fragment manager that the state is not saved. If you are handling new intents and may be making changes to the fragment state, you want to be sure to call through to the super-class here first. Otherwise, if your state is saved but the activity is not stopped, you could get an onNewIntent() call which happens before onResume() and trying to perform fragment operations at that point will throw IllegalStateException because the fragment manager thinks the state is still saved.

Overrides:
onNewIntent in class android.app.Activity

onResume

protected void onResume()
Dispatch onResume() to fragments. Note that for better inter-operation with older versions of the platform, at the point of this call the fragments attached to the activity are not resumed. This means that in some cases the previous state may still be saved, not allowing fragment transactions that modify the state. To correctly interact with fragments in their proper state, you should instead override onResumeFragments().

Overrides:
onResume in class android.app.Activity

onPostResume

protected void onPostResume()
Dispatch onResume() to fragments.

Overrides:
onPostResume in class android.app.Activity

onResumeFragments

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. Be sure to always call through to the super-class.


onPreparePanel

public boolean onPreparePanel(int featureId,
                              android.view.View view,
                              android.view.Menu menu)
Dispatch onPrepareOptionsMenu() to fragments.

Specified by:
onPreparePanel in interface android.view.Window.Callback
Overrides:
onPreparePanel in class android.app.Activity

onRetainNonConfigurationInstance

public final Object onRetainNonConfigurationInstance()
Retain all appropriate fragment and loader state. You can NOT override this yourself! Use onRetainCustomNonConfigurationInstance() if you want to retain your own state.

Overrides:
onRetainNonConfigurationInstance in class android.app.Activity

onSaveInstanceState

protected void onSaveInstanceState(android.os.Bundle outState)
Save all appropriate fragment state.

Overrides:
onSaveInstanceState in class android.app.Activity

onStart

protected void onStart()
Dispatch onStart() to all fragments. Ensure any created loaders are now started.

Overrides:
onStart in class android.app.Activity

onStop

protected void onStop()
Dispatch onStop() to all fragments. Ensure all loaders are stopped.

Overrides:
onStop in class android.app.Activity

onRetainCustomNonConfigurationInstance

public Object onRetainCustomNonConfigurationInstance()
Use this instead of onRetainNonConfigurationInstance(). Retrieve later with getLastCustomNonConfigurationInstance().


getLastCustomNonConfigurationInstance

public Object getLastCustomNonConfigurationInstance()
Return the value previously returned from onRetainCustomNonConfigurationInstance().


supportInvalidateOptionsMenu

public void supportInvalidateOptionsMenu()
Invalidate the activity's options menu. This will cause relevant presentations of the menu to fully update via calls to onCreateOptionsMenu and onPrepareOptionsMenu the next time the menu is requested.


dump

public void dump(String prefix,
                 FileDescriptor fd,
                 PrintWriter writer,
                 String[] args)
Print the Activity's state into the given stream. This gets invoked if you run "adb shell dumpsys activity ".

Overrides:
dump in class android.app.Activity
Parameters:
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.

onAttachFragment

public void onAttachFragment(Fragment fragment)
Called when a fragment is attached to the activity.


getSupportFragmentManager

public FragmentManager getSupportFragmentManager()
Return the FragmentManager for interacting with fragments associated with this activity.


startActivityForResult

public void startActivityForResult(android.content.Intent intent,
                                   int requestCode)
Modifies the standard behavior to allow results to be delivered to fragments. This imposes a restriction that requestCode be <= 0xffff.

Overrides:
startActivityForResult in class android.app.Activity

startActivityFromFragment

public void startActivityFromFragment(Fragment fragment,
                                      android.content.Intent intent,
                                      int requestCode)
Called by Fragment.startActivityForResult() to implement its behavior.


getSupportLoaderManager

public LoaderManager getSupportLoaderManager()
Return the LoaderManager for this fragment, creating it if needed.



Copyright © 2013 Marek Kedzierski. All Rights Reserved.