android.support.v4.app
Class ActivityCompat

java.lang.Object
  extended by android.support.v4.content.ContextCompat
      extended by android.support.v4.app.ActivityCompat

public class ActivityCompat
extends ContextCompat

Helper for accessing features in Activity introduced after API level 4 in a backwards compatible fashion.


Constructor Summary
ActivityCompat()
           
 
Method Summary
static boolean invalidateOptionsMenu(android.app.Activity activity)
          Invalidate the activity's options menu, if able.
static void startActivity(android.app.Activity activity, android.content.Intent intent, android.os.Bundle options)
          Start an activity with additional launch information, if able.
static void startActivityForResult(android.app.Activity activity, android.content.Intent intent, int requestCode, android.os.Bundle options)
          Start new activity with options, if able, for which you would like a result when it finished.
 
Methods inherited from class android.support.v4.content.ContextCompat
startActivities, startActivities
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActivityCompat

public ActivityCompat()
Method Detail

invalidateOptionsMenu

public static boolean invalidateOptionsMenu(android.app.Activity activity)
Invalidate the activity's options menu, if able.

Before API level 11 (Android 3.0/Honeycomb) the lifecycle of the options menu was controlled primarily by the user's operation of the hardware menu key. When the user presses down on the menu key for the first time the menu was created and prepared by calls to Activity.onCreateOptionsMenu(android.view.Menu) and Activity.onPrepareOptionsMenu(android.view.Menu) respectively. Subsequent presses of the menu key kept the existing instance of the Menu itself and called Activity.onPrepareOptionsMenu(android.view.Menu) to give the activity an opportunity to contextually alter the menu before the menu panel was shown.

In Android 3.0+ the Action Bar forces the options menu to be built early so that items chosen to show as actions may be displayed when the activity first becomes visible. The Activity method invalidateOptionsMenu forces the entire menu to be destroyed and recreated from Activity.onCreateOptionsMenu(android.view.Menu), offering a similar though heavier-weight opportunity to change the menu's contents. Normally this functionality is used to support a changing configuration of Fragments.

Applications may use this support helper to signal a significant change in activity state that should cause the options menu to be rebuilt. If the app is running on an older platform version that does not support menu invalidation the app will still receive Activity.onPrepareOptionsMenu(android.view.Menu) the next time the user presses the menu key and this method will return false. If this method returns true the options menu was successfully invalidated.

Parameters:
activity - Invalidate the options menu of this activity
Returns:
true if this operation was supported and it completed; false if it was not available.

startActivity

public static void startActivity(android.app.Activity activity,
                                 android.content.Intent intent,
                                 android.os.Bundle options)
Start an activity with additional launch information, if able.

In Android 4.1+ additional options were introduced to allow for more control on activity launch animations. Applications can use this method along with ActivityOptionsCompat to use these animations when available. When run on versions of the platform where this feature does not exist the activity will be launched normally.

Parameters:
activity - Context to launch activity from.
intent - The description of the activity to start.
options - Additional options for how the Activity should be started. May be null if there are no options. See ActivityOptionsCompat for how to build the Bundle supplied here; there are no supported definitions for building it manually.

startActivityForResult

public static void startActivityForResult(android.app.Activity activity,
                                          android.content.Intent intent,
                                          int requestCode,
                                          android.os.Bundle options)
Start new activity with options, if able, for which you would like a result when it finished.

In Android 4.1+ additional options were introduced to allow for more control on activity launch animations. Applications can use this method along with ActivityOptionsCompat to use these animations when available. When run on versions of the platform where this feature does not exist the activity will be launched normally.

Parameters:
activity - Origin activity to launch from.
intent - The description of the activity to start.
requestCode - If >= 0, this code will be returned in onActivityResult() when the activity exits.
options - Additional options for how the Activity should be started. May be null if there are no options. See ActivityOptionsCompat for how to build the Bundle supplied here; there are no supported definitions for building it manually.


Copyright © 2013 Marek Kedzierski. All Rights Reserved.