NavUtils
class 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 |
|
|---|---|
const String! |
PARENT_ACTIVITY = "android.support.PARENT_ACTIVITY" |
Public functions |
|
|---|---|
java-static Intent? |
getParentActivityIntent(sourceActivity: Activity)Obtain an |
java-static Intent? |
getParentActivityIntent(context: Context, componentName: ComponentName)Obtain an |
java-static Intent? |
getParentActivityIntent(context: Context, sourceActivityClass: Class<*>)Obtain an |
java-static String? |
getParentActivityName(sourceActivity: Activity)Return the fully qualified class name of sourceActivity's parent activity as specified by a |
java-static String? |
getParentActivityName(context: Context, componentName: ComponentName)Return the fully qualified class name of a source activity's parent activity as specified by a |
java-static Unit |
navigateUpFromSameTask(sourceActivity: Activity)Convenience method that is equivalent to calling |
java-static Unit |
@ReplaceWith(expression = "sourceActivity.navigateUpTo(upIntent)")This function is deprecated. Call navigateUpTo directly. |
java-static Boolean |
@ReplaceWith(expression = "sourceActivity.shouldUpRecreateTask(targetIntent)")This function is deprecated. Call shouldUpRecreateTask directly. |
Constants
PARENT_ACTIVITY
const val PARENT_ACTIVITY = "android.support.PARENT_ACTIVITY": String!
Public functions
getParentActivityIntent
java-static fun getParentActivityIntent(sourceActivity: Activity): Intent?
Obtain an Intent that will launch an explicit target activity specified by sourceActivity's PARENT_ACTIVITY
| Parameters | |
|---|---|
sourceActivity: Activity |
Activity to fetch a parent intent for |
| Returns | |
|---|---|
Intent? |
a new Intent targeting the defined parent activity of sourceActivity |
getParentActivityIntent
java-static fun getParentActivityIntent(context: Context, componentName: ComponentName): Intent?
Obtain an Intent that will launch an explicit target activity specified by sourceActivityClass's PARENT_ACTIVITY
| 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 | |
|---|---|
android.content.pm.PackageManager.NameNotFoundException |
if the ComponentName for sourceActivityClass is invalid |
getParentActivityIntent
java-static fun getParentActivityIntent(context: Context, sourceActivityClass: Class<*>): Intent?
Obtain an Intent that will launch an explicit target activity specified by sourceActivityClass's PARENT_ACTIVITY
| Parameters | |
|---|---|
context: Context |
Context for looking up the activity component for sourceActivityClass |
sourceActivityClass: Class<*> |
|
| Returns | |
|---|---|
Intent? |
a new Intent targeting the defined parent activity of sourceActivity |
| Throws | |
|---|---|
android.content.pm.PackageManager.NameNotFoundException |
if the ComponentName for sourceActivityClass is invalid |
getParentActivityName
java-static fun getParentActivityName(sourceActivity: Activity): String?
Return the fully qualified class name of sourceActivity's parent activity as specified by a PARENT_ACTIVITY
| Parameters | |
|---|---|
sourceActivity: Activity |
Activity to fetch a parent class name for |
| Returns | |
|---|---|
String? |
The fully qualified class name of sourceActivity's parent activity or null if it was not specified |
getParentActivityName
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 PARENT_ACTIVITY
| Parameters | |
|---|---|
context: Context |
Context for looking up the activity component for the source activity |
componentName: ComponentName |
ComponentName for the source Activity |
| Returns | |
|---|---|
String? |
The fully qualified class name of sourceActivity's parent activity or null if it was not specified |
navigateUpFromSameTask
java-static fun navigateUpFromSameTask(sourceActivity: Activity): Unit
Convenience method that is equivalent to calling . sourceActivity will be finished by this call. navigateUpTo(sourceActivity,
getParentActivityIntent (sourceActivity))
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.
| Parameters | |
|---|---|
sourceActivity: Activity |
The current activity from which the user is attempting to navigate up |
@ReplaceWith(expression = "sourceActivity.navigateUpTo(upIntent)")
java-static funnavigateUpTo(sourceActivity: Activity, upIntent: Intent): Unit
Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process. upIntent will have the flag 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.
@ReplaceWith(expression = "sourceActivity.shouldUpRecreateTask(targetIntent)")
java-static funshouldUpRecreateTask(sourceActivity: Activity, targetIntent: Intent): Boolean
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 using the same parameters to correctly perform up navigation. If this method returns true, the app should synthesize a new task stack by using TaskStackBuilder or another similar mechanism to perform up navigation.
| Parameters | |
|---|---|
sourceActivity: Activity |
The current activity from which the user is attempting to navigate up |
targetIntent: Intent |
An intent representing the target destination for up navigation |
| Returns | |
|---|---|
Boolean |
true if navigating up should recreate a new task stack, false if the same task should be used for the destination |