Navigation


public final class Navigation


The Navigation instance passed by NavigationListener.

The same object will be used by the relevant callbacks for the same navigation, allowing the instance itself to be used as a key/ID to connect the callbacks for the same navigation through equals and hashCode.

The return values of wasInitiatedByPage, isReload, isHistory, isBack, isForward and isRestore are constant for a given Navigation. For the other methods:

Summary

Public methods

boolean

Indicates whether the navigation committed (i.e., did not get aborted/return 204/etc).

boolean

Indicates whether the navigation committed an error page.

@Nullable Page

Returns the Page that the navigation commits into.

int

Returns the status code received by the navigation.

@NonNull String

Returns the URL of this navigation.

@Nullable WebResourceErrorCompat
@RequiresFeature(name = WebViewFeature.NAVIGATION_GET_WEB_RESOURCE_ERROR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
getWebResourceError()

Navigation error information for the navigation load.

boolean

Indicates whether the navigation is a history back navigation.

boolean

Indicates whether the navigation is a history forward navigation.

boolean

Indicates whether the navigation is a history navigation.

boolean

Indicates whether the navigation is a reload navigation.

boolean

Indicates whether the navigation is a restore navigation after calling restoreState.

boolean

Indicates whether the navigation is a same-document navigation.

boolean

Indicates whether the navigation is initiated by the page/renderer (e.g., link clicks, JS script) instead of the browser/app (e.g., loadUrl calls).

Public methods

didCommit

Added in 1.14.0
public boolean didCommit()

Indicates whether the navigation committed (i.e., did not get aborted/return 204/etc).

Returns
boolean

True if committed, false otherwise.

didCommitErrorPage

Added in 1.14.0
public boolean didCommitErrorPage()

Indicates whether the navigation committed an error page.

Returns
boolean

True if an error page was committed, false otherwise.

getPage

Added in 1.14.0
public @Nullable Page getPage()

Returns the Page that the navigation commits into.

Note: This method will initially return null when navigation begins. If the navigation successfully commits a page, this method will return the corresponding Page object. This could be a newly created Page or a previously seen Page in the case of BFCache (Back/Forward Cache).

Note: Once this method returns a non-null Page object for a specific navigation, it will always return the same Page object for that navigation.

Returns
@Nullable Page

The Page object, or null if the navigation does not commit or result in a Page (e.g., 204/download).

getStatusCode

Added in 1.14.0
public int getStatusCode()

Returns the status code received by the navigation.

Returns
int

The HTTP status code.

getUrl

Added in 1.15.0
public @NonNull String getUrl()

Returns the URL of this navigation.

Returns
@NonNull String

The URL of this navigation as a String.

getWebResourceError

@RequiresFeature(name = WebViewFeature.NAVIGATION_GET_WEB_RESOURCE_ERROR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @Nullable WebResourceErrorCompat getWebResourceError()

Navigation error information for the navigation load.

This method should only be called if isFeatureSupported returns true for NAVIGATION_LISTENER.

Returns
@Nullable WebResourceErrorCompat

The WebResourceErrorCompat object, or null if there is no error for this navigation.

isBack

Added in 1.14.0
public boolean isBack()

Indicates whether the navigation is a history back navigation.

Returns
boolean

True if back navigation, false otherwise.

isForward

Added in 1.14.0
public boolean isForward()

Indicates whether the navigation is a history forward navigation.

Returns
boolean

True if forward navigation, false otherwise.

isHistory

Added in 1.14.0
public boolean isHistory()

Indicates whether the navigation is a history navigation.

Returns
boolean

True if history, false otherwise.

isReload

Added in 1.14.0
public boolean isReload()

Indicates whether the navigation is a reload navigation.

Returns
boolean

True if reload, false otherwise.

isRestore

Added in 1.14.0
public boolean isRestore()

Indicates whether the navigation is a restore navigation after calling restoreState.

Returns
boolean

True if session restore, false otherwise.

isSameDocument

Added in 1.14.0
public boolean isSameDocument()

Indicates whether the navigation is a same-document navigation.

Returns
boolean

True if same-document, false otherwise.

wasInitiatedByPage

Added in 1.14.0
public boolean wasInitiatedByPage()

Indicates whether the navigation is initiated by the page/renderer (e.g., link clicks, JS script) instead of the browser/app (e.g., loadUrl calls).

Returns
boolean

True if page-initiated, false otherwise.