Most visited

Recently visited

NavUtils

public final class NavUtils
extends Object

java.lang.Object
   ↳ android.support.v4.app.NavUtils


NavUtils为实施推荐的Android UI导航模式的应用程序提供帮助功能。 有关建议的导航模式信息,请参阅Tasks and Back Stack从开发者指南和Navigation从设计指导。

Summary

Constants

String PARENT_ACTIVITY

Public methods

static Intent getParentActivityIntent(Context context, ComponentName componentName)

获取一个 Intent ,它将启动由应用程序清单中的sourceActivityClass的 PARENT_ACTIVITY <meta-data>元素指定的显式目标活动。

static Intent getParentActivityIntent(Context context, Class<?> sourceActivityClass)

获取一个 Intent ,它将启动由应用程序清单中的sourceActivityClass的 PARENT_ACTIVITY <meta-data>元素指定的显式目标活动。

static Intent getParentActivityIntent(Activity sourceActivity)

获取一个 Intent ,它将启动由应用程序清单中的sourceActivity的 PARENT_ACTIVITY <meta-data>元素指定的显式目标活动。

static String getParentActivityName(Context context, ComponentName componentName)

按照应用程序清单中activity元素内的 PARENT_ACTIVITY <meta-data>元素的指定返回源活动的父活动的完全限定类名称。

static String getParentActivityName(Activity sourceActivity)

按照应用程序清单中activity元素内的 PARENT_ACTIVITY <meta-data>元素的指定返回sourceActivity父级活动的完全限定类名称。

static void navigateUpFromSameTask(Activity sourceActivity)

便捷方法相当于拨打 navigateUpTo(sourceActivity, getParentActivityIntent (sourceActivity))

static void navigateUpTo(Activity sourceActivity, Intent upIntent)

从sourceActivity导航到由upIntent指定的活动,在流程中完成sourceActivity。

static boolean shouldUpRecreateTask(Activity sourceActivity, Intent targetIntent)

如果sourceActivity在使用targetIntent导航'up'时重新创建任务,则返回true。

Inherited methods

From class java.lang.Object

Constants

PARENT_ACTIVITY

String PARENT_ACTIVITY

常量值:“android.support.PARENT_ACTIVITY”

Public methods

getParentActivityIntent

Intent getParentActivityIntent (Context context, 
                ComponentName componentName)

获取一个 Intent ,它将启动由应用程序清单中的sourceActivityClass的 PARENT_ACTIVITY <meta-data>元素指定的显式目标活动。

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

Intent getParentActivityIntent (Context context, 
                Class<?> sourceActivityClass)

获取一个 Intent ,它将启动由应用程序清单中的sourceActivityClass的 PARENT_ACTIVITY <meta-data>元素指定的显式目标活动。

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

Intent getParentActivityIntent (Activity sourceActivity)

获取一个Intent ,它将启动由应用程序清单中的sourceActivity PARENT_ACTIVITY <meta-data>元素指定的显式目标活动。 如果设备运行Jellybean或更新,则android:parentActivityName属性将首选(如果存在)。

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

getParentActivityName

String getParentActivityName (Context context, 
                ComponentName componentName)

按照应用程序清单中activity元素内的PARENT_ACTIVITY <meta-data>元素的指定返回源活动的父活动的完全限定类名称。 源活动由componentName提供。

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
Throws
PackageManager.NameNotFoundException

getParentActivityName

String getParentActivityName (Activity sourceActivity)

按照应用程序清单中activity元素内的 PARENT_ACTIVITY <meta-data>元素的指定返回sourceActivity父级活动的完全限定类名称。

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

navigateUpFromSameTask

void navigateUpFromSameTask (Activity sourceActivity)

相当于拨打navigateUpTo(sourceActivity, getParentActivityIntent (sourceActivity))便捷方法。 此活动将完成sourceActivity。

注意:只有当sourceActivity和相应的父项在同一个任务中时才应使用此方法。 如果在某些情况下向上导航应该跨越任务,请参阅shouldUpRecreateTask(Activity, Intent)

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

navigateUpTo

void navigateUpTo (Activity sourceActivity, 
                Intent upIntent)

从sourceActivity导航到由upIntent指定的活动,在流程中完成sourceActivity。 upIntent将拥有由此方法设置的标志FLAG_ACTIVITY_CLEAR_TOP以及Android设计指南中概述的正确导航所需的其他标志。

在与目的地相同的任务内执行导航时应使用此方法。 如果在某些情况下向上导航应该跨越任务,请参阅shouldUpRecreateTask(Activity, Intent)

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

shouldUpRecreateTask

boolean shouldUpRecreateTask (Activity sourceActivity, 
                Intent targetIntent)

如果sourceActivity在使用targetIntent导航'up'时重新创建任务,则返回true。

如果此方法返回false,则应用程序可以使用相同参数调用navigateUpTo(Activity, Intent)以正确执行导航。 如果此方法返回true,则应用程序应使用TaskStackBuilder或其他类似的机制来合成新的任务堆栈以执行导航。

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

Hooray!