NavUtils

public final class NavUtils
extends Object

java.lang.Object
   ↳ androidx.core.app.NavUtils


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.

Summary

Constants

String PARENT_ACTIVITY

Public methods

static Intent getParentActivityIntent(Context context, 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 Intent getParentActivityIntent(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 Intent getParentActivityIntent(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 String getParentActivityName(Context context, 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 String getParentActivityName(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 void navigateUpFromSameTask(Activity sourceActivity)

Convenience method that is equivalent to calling navigateUpTo(sourceActivity, getParentActivityIntent (sourceActivity)).

static void navigateUpTo(Activity sourceActivity, Intent upIntent)

Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process.

static boolean shouldUpRecreateTask(Activity sourceActivity, Intent targetIntent)

Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent.

Inherited methods

Constants

PARENT_ACTIVITY

public static final String PARENT_ACTIVITY

Constant Value: "android.support.PARENT_ACTIVITY"

Public methods

getParentActivityIntent

public static Intent getParentActivityIntent (Context context, 
                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.

Parameters
context Context: Context for looking up the activity component for the source activity

componentName ComponentName: ComponentName for the source Activity

Returns
Intent a new Intent targeting the defined parent activity of sourceActivity

Throws
PackageManager.NameNotFoundException if the ComponentName for sourceActivityClass is invalid

getParentActivityIntent

public static Intent getParentActivityIntent (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.

Parameters
context Context: Context for looking up the activity component for sourceActivityClass

sourceActivityClass Class: Class object for an Activity class

Returns
Intent a new Intent targeting the defined parent activity of sourceActivity

Throws
PackageManager.NameNotFoundException if the ComponentName for sourceActivityClass is invalid

getParentActivityIntent

public static Intent getParentActivityIntent (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: Activity to fetch a parent intent for

Returns
Intent a new Intent targeting the defined parent activity of sourceActivity

getParentActivityName