# NavUtils

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/app/NavUtils.java+class:androidx.core.app.NavUtils) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

<br />

```
class NavUtils
```

<br />

*** ** * ** ***

NavUtils provides helper functionality for applications implementing recommended Android UI navigation patterns. For information about recommended navigation patterns see [Tasks and Back Stack](https://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack) from the developer guide and [Navigation](https://developer.android.com/design/patterns/navigation) from the design guide.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY() = "android.support.PARENT_ACTIVITY"` |

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/android/content/Intent.html?` | `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#getParentActivityIntent(android.app.Activity)(sourceActivity: https://developer.android.com/reference/android/app/Activity.html)` Obtain an `https://developer.android.com/reference/android/content/Intent.html` that will launch an explicit target activity specified by sourceActivity's `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element in the application's manifest. |
| `java-static https://developer.android.com/reference/android/content/Intent.html?` | `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#getParentActivityIntent(android.content.Context,android.content.ComponentName)(context: https://developer.android.com/reference/android/content/Context.html, componentName: https://developer.android.com/reference/android/content/ComponentName.html)` Obtain an `https://developer.android.com/reference/android/content/Intent.html` that will launch an explicit target activity specified by sourceActivityClass's `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element in the application's manifest. |
| `java-static https://developer.android.com/reference/android/content/Intent.html?` | `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#getParentActivityIntent(android.content.Context,java.lang.Class<?>)(context: https://developer.android.com/reference/android/content/Context.html, sourceActivityClass: https://developer.android.com/reference/java/lang/Class.html<*>)` Obtain an `https://developer.android.com/reference/android/content/Intent.html` that will launch an explicit target activity specified by sourceActivityClass's `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element in the application's manifest. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#getParentActivityName(android.app.Activity)(sourceActivity: https://developer.android.com/reference/android/app/Activity.html)` Return the fully qualified class name of sourceActivity's parent activity as specified by a `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element within the activity element in the application's manifest. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#getParentActivityName(android.content.Context,android.content.ComponentName)(context: https://developer.android.com/reference/android/content/Context.html, componentName: https://developer.android.com/reference/android/content/ComponentName.html)` Return the fully qualified class name of a source activity's parent activity as specified by a `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element within the activity element in the application's manifest. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#navigateUpFromSameTask(android.app.Activity)(sourceActivity: https://developer.android.com/reference/android/app/Activity.html)` Convenience method that is equivalent to calling `` `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#navigateUpTo(android.app.Activity,android.content.Intent)`(sourceActivity, `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#getParentActivityIntent(android.app.Activity)` (sourceActivity)) ``. sourceActivity will be finished by this call. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith(expression = "sourceActivity.navigateUpTo(upIntent)") [navigateUpTo](https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#navigateUpTo(android.app.Activity,android.content.Intent))(sourceActivity: https://developer.android.com/reference/android/app/Activity.html, upIntent: https://developer.android.com/reference/android/content/Intent.html)` **This function is deprecated.** Call navigateUpTo directly. <br /> |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith(expression = "sourceActivity.shouldUpRecreateTask(targetIntent)") [shouldUpRecreateTask](https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#shouldUpRecreateTask(android.app.Activity,android.content.Intent))(sourceActivity: https://developer.android.com/reference/android/app/Activity.html, targetIntent: https://developer.android.com/reference/android/content/Intent.html)` **This function is deprecated.** Call shouldUpRecreateTask directly. <br /> |

## Constants

### PARENT_ACTIVITY

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
const val PARENT_ACTIVITY = "android.support.PARENT_ACTIVITY": String!
```

## Public functions

### getParentActivityIntent

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun getParentActivityIntent(sourceActivity: Activity): Intent?
```

Obtain an `https://developer.android.com/reference/android/content/Intent.html` that will launch an explicit target activity specified by sourceActivity's `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element in the application's manifest. The android:parentActivityName attribute will be preferred if it is present.

| Parameters |
|---|---|
| `sourceActivity: https://developer.android.com/reference/android/app/Activity.html` | Activity to fetch a parent intent for |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html?` | a new Intent targeting the defined parent activity of sourceActivity |

### getParentActivityIntent

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun getParentActivityIntent(context: Context, componentName: ComponentName): Intent?
```

Obtain an `https://developer.android.com/reference/android/content/Intent.html` that will launch an explicit target activity specified by sourceActivityClass's `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element in the application's manifest.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | Context for looking up the activity component for the source activity |
| `componentName: https://developer.android.com/reference/android/content/ComponentName.html` | ComponentName for the source Activity |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html?` | a new Intent targeting the defined parent activity of sourceActivity |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.NameNotFoundException.html` | if the ComponentName for sourceActivityClass is invalid |

### getParentActivityIntent

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun getParentActivityIntent(context: Context, sourceActivityClass: Class<*>): Intent?
```

Obtain an `https://developer.android.com/reference/android/content/Intent.html` that will launch an explicit target activity specified by sourceActivityClass's `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element in the application's manifest.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | Context for looking up the activity component for sourceActivityClass |
| `sourceActivityClass: https://developer.android.com/reference/java/lang/Class.html<*>` | `https://developer.android.com/reference/java/lang/Class.html` object for an Activity class |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html?` | a new Intent targeting the defined parent activity of sourceActivity |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.NameNotFoundException.html` | if the ComponentName for sourceActivityClass is invalid |

### getParentActivityName

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun getParentActivityName(sourceActivity: Activity): String?
```

Return the fully qualified class name of sourceActivity's parent activity as specified by a `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element within the activity element in the application's manifest.

| Parameters |
|---|---|
| `sourceActivity: https://developer.android.com/reference/android/app/Activity.html` | Activity to fetch a parent class name for |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The fully qualified class name of sourceActivity's parent activity or null if it was not specified |

### getParentActivityName

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun getParentActivityName(context: Context, componentName: ComponentName): String?
```

Return the fully qualified class name of a source activity's parent activity as specified by a `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#PARENT_ACTIVITY()` element within the activity element in the application's manifest. The source activity is provided by componentName.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | Context for looking up the activity component for the source activity |
| `componentName: https://developer.android.com/reference/android/content/ComponentName.html` | ComponentName for the source Activity |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The fully qualified class name of sourceActivity's parent activity or null if it was not specified |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.NameNotFoundException.html` |   |

### navigateUpFromSameTask

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun navigateUpFromSameTask(sourceActivity: Activity): Unit
```

Convenience method that is equivalent to calling `` `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#navigateUpTo(android.app.Activity,android.content.Intent)`(sourceActivity, `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#getParentActivityIntent(android.app.Activity)` (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 `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#shouldUpRecreateTask(android.app.Activity,android.content.Intent)`.

| Parameters |
|---|---|
| `sourceActivity: https://developer.android.com/reference/android/app/Activity.html` | The current activity from which the user is attempting to navigate up |

### navigateUpTo

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.15.0](https://developer.android.com/jetpack/androidx/releases/core#1.15.0)

```
@ReplaceWith(expression = "sourceActivity.navigateUpTo(upIntent)")
java-static fun [navigateUpTo](https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#navigateUpTo(android.app.Activity,android.content.Intent))(sourceActivity: Activity, upIntent: Intent): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Call navigateUpTo directly.

Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process. upIntent will have the flag `https://developer.android.com/reference/android/content/Intent.html#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 `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#shouldUpRecreateTask(android.app.Activity,android.content.Intent)`.

| Parameters |
|---|---|
| `sourceActivity: https://developer.android.com/reference/android/app/Activity.html` | The current activity from which the user is attempting to navigate up |
| `upIntent: https://developer.android.com/reference/android/content/Intent.html` | An intent representing the target destination for up navigation |

### shouldUpRecreateTask

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.15.0](https://developer.android.com/jetpack/androidx/releases/core#1.15.0)

```
@ReplaceWith(expression = "sourceActivity.shouldUpRecreateTask(targetIntent)")
java-static fun [shouldUpRecreateTask](https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#shouldUpRecreateTask(android.app.Activity,android.content.Intent))(sourceActivity: Activity, targetIntent: Intent): Boolean
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Call shouldUpRecreateTask directly.

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

If this method returns false the app can trivially call `https://developer.android.com/reference/kotlin/androidx/core/app/NavUtils#navigateUpTo(android.app.Activity,android.content.Intent)` using the same parameters to correctly perform up navigation. If this method returns true, the app should synthesize a new task stack by using `https://developer.android.com/reference/kotlin/androidx/core/app/TaskStackBuilder` or another similar mechanism to perform up navigation.

| Parameters |
|---|---|
| `sourceActivity: https://developer.android.com/reference/android/app/Activity.html` | The current activity from which the user is attempting to navigate up |
| `targetIntent: https://developer.android.com/reference/android/content/Intent.html` | An intent representing the target destination for up navigation |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if navigating up should recreate a new task stack, false if the same task should be used for the destination |