android.support.v4.app
Class NavUtils

java.lang.Object
  extended by android.support.v4.app.NavUtils

public class NavUtils
extends Object

NavUtils provides helper functionality for applications implementing recommended Android UI navigation patterns. For information about recommended navigation patterns see Tasks and Back Stack from the developer guide and Navigation from the design guide.


Field Summary
static String PARENT_ACTIVITY
           
 
Method Summary
static android.content.Intent getParentActivityIntent(android.app.Activity sourceActivity)
          Obtain an Intent that will launch an explicit target activity specified by sourceActivity's PARENT_ACTIVITY <meta-data> element in the application's manifest.
static android.content.Intent getParentActivityIntent(android.content.Context context, Class<?> sourceActivityClass)
          Obtain an Intent that will launch an explicit target activity specified by sourceActivityClass's PARENT_ACTIVITY <meta-data> element in the application's manifest.
static android.content.Intent getParentActivityIntent(android.content.Context context, android.content.ComponentName componentName)
          Obtain an Intent that will launch an explicit target activity specified by sourceActivityClass's PARENT_ACTIVITY <meta-data> element in the application's manifest.
static String getParentActivityName(android.app.Activity sourceActivity)
          Return the fully qualified class name of sourceActivity's parent activity as specified by a PARENT_ACTIVITY <meta-data> element within the activity element in the application's manifest.
static String getParentActivityName(android.content.Context context, android.content.ComponentName componentName)
          Return the fully qualified class name of a source activity's parent activity as specified by a PARENT_ACTIVITY <meta-data> element within the activity element in the application's manifest.
static void navigateUpFromSameTask(android.app.Activity sourceActivity)
          Convenience method that is equivalent to calling navigateUpTo(sourceActivity, getParentActivityIntent (sourceActivity)).
static void navigateUpTo(android.app.Activity sourceActivity, android.content.Intent upIntent)
          Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process. upIntent will have the flag Intent.FLAG_ACTIVITY_CLEAR_TOP set by this method, along with any others required for proper up navigation as outlined in the Android Design Guide.
static boolean shouldUpRecreateTask(android.app.Activity sourceActivity, android.content.Intent targetIntent)
          Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARENT_ACTIVITY

public static final String PARENT_ACTIVITY
See Also:
Constant Field Values
Method Detail

shouldUpRecreateTask

public static boolean shouldUpRecreateTask(android.app.Activity sourceActivity,
                                           android.content.Intent targetIntent)
Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent.

If this method returns false the app can trivially call navigateUpTo(Activity, Intent) using the same parameters to correctly perform up navigation. If this method returns false, the app should synthesize a new task stack by using TaskStackBuilder or another similar mechanism to perform up navigation.

Parameters:
sourceActivity - The current activity from which the user is attempting to navigate up
targetIntent - An intent representing the target destination for up navigation
Returns:
true if navigating up should recreate a new task stack, false if the same task should be used for the destination

navigateUpFromSameTask

public static void navigateUpFromSameTask(android.app.Activity sourceActivity)
Convenience method that is equivalent to calling navigateUpTo(sourceActivity, getParentActivityIntent (sourceActivity)). sourceActivity will be finished by this call.

Note: This method should only be used when sourceActivity and the corresponding parent are within the same task. If up navigation should cross tasks in some cases, see shouldUpRecreateTask(Activity, Intent).

Parameters:
sourceActivity - The current activity from which the user is attempting to navigate up

navigateUpTo

public static void navigateUpTo(android.app.Activity sourceActivity,
                                android.content.Intent upIntent)
Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process. upIntent will have the flag Intent.FLAG_ACTIVITY_CLEAR_TOP set by this method, along with any others required for proper up navigation as outlined in the Android Design Guide.

This method should be used when performing up navigation from within the same task as the destination. If up navigation should cross tasks in some cases, see shouldUpRecreateTask(Activity, Intent).

Parameters:
sourceActivity - The current activity from which the user is attempting to navigate up
upIntent - An intent representing the target destination for up navigation

getParentActivityIntent

public static android.content.Intent getParentActivityIntent(android.app.Activity sourceActivity)
Obtain an Intent that will launch an explicit target activity specified by sourceActivity's PARENT_ACTIVITY <meta-data> element in the application's manifest. If the device is running Jellybean or newer, the android:parentActivityName attribute will be preferred if it is present.

Parameters:
sourceActivity - Activity to fetch a parent intent for
Returns:
a new Intent targeting the defined parent activity of sourceActivity

getParentActivityIntent

public static android.content.Intent getParentActivityIntent(android.content.Context context,
                                                             Class<?> sourceActivityClass)
                                                      throws android.content.pm.PackageManager.NameNotFoundException
Obtain an Intent that will launch an explicit target activity specified by sourceActivityClass's PARENT_ACTIVITY <meta-data> element in the application's manifest.

Parameters:
context - Context for looking up the activity component for sourceActivityClass
sourceActivityClass - Class object for an Activity class
Returns:
a new Intent targeting the defined parent activity of sourceActivity
Throws:
android.content.pm.PackageManager.NameNotFoundException - if the ComponentName for sourceActivityClass is invalid

getParentActivityIntent

public static android.content.Intent getParentActivityIntent(android.content.Context context,
                                                             android.content.ComponentName componentName)
                                                      throws android.content.pm.PackageManager.NameNotFoundException
Obtain an Intent that will launch an explicit target activity specified by sourceActivityClass's PARENT_ACTIVITY <meta-data> element in the application's manifest.

Parameters:
context - Context for looking up the activity component for the source activity
componentName - ComponentName for the source Activity
Returns:
a new Intent targeting the defined parent activity of sourceActivity
Throws:
android.content.pm.PackageManager.NameNotFoundException - if the ComponentName for sourceActivityClass is invalid

getParentActivityName

public static String getParentActivityName(android.app.Activity sourceActivity)
Return the fully qualified class name of sourceActivity's parent activity as specified by a PARENT_ACTIVITY <meta-data> element within the activity element in the application's manifest.

Parameters:
sourceActivity - Activity to fetch a parent class name for
Returns:
The fully qualified class name of sourceActivity's parent activity or null if it was not specified

getParentActivityName

public static String getParentActivityName(android.content.Context context,
                                           android.content.ComponentName componentName)
                                    throws android.content.pm.PackageManager.NameNotFoundException
Return the fully qualified class name of a source activity's parent activity as specified by a PARENT_ACTIVITY <meta-data> element within the activity element in the application's manifest. The source activity is provided by componentName.

Parameters:
context - Context for looking up the activity component for the source activity
componentName - ComponentName for the source Activity
Returns:
The fully qualified class name of sourceActivity's parent activity or null if it was not specified
Throws:
android.content.pm.PackageManager.NameNotFoundException


Copyright © 2013 Marek Kedzierski. All Rights Reserved.