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:
getPage,didCommitanddidCommitErrorPagewill only change whenonNavigationCompletedis called.getUrlwill only change whenonNavigationRedirectedis called.
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 |
getPage()Returns the Page that the navigation commits into. |
int |
Returns the status code received by the navigation. |
@NonNull String |
getUrl()Returns the URL of this navigation. |
@Nullable WebResourceErrorCompat |
@RequiresFeature(name = WebViewFeature.NAVIGATION_GET_WEB_RESOURCE_ERROR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Navigation error information for the navigation load. |
boolean |
isBack()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 |
isReload()Indicates whether the navigation is a reload navigation. |
boolean |
Indicates whether the navigation is a restore navigation after calling |
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
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
public boolean didCommitErrorPage()
Indicates whether the navigation committed an error page.
| Returns | |
|---|---|
boolean |
True if an error page was committed, false otherwise. |
getPage
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.
getStatusCode
public int getStatusCode()
Returns the status code received by the navigation.
| Returns | |
|---|---|
int |
The HTTP status code. |
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.
| Returns | |
|---|---|
@Nullable WebResourceErrorCompat |
The |
| Throws | |
|---|---|
java.lang.UnsupportedOperationException |
if the |
isBack
public boolean isBack()
Indicates whether the navigation is a history back navigation.
| Returns | |
|---|---|
boolean |
True if back navigation, false otherwise. |
isForward
public boolean isForward()
Indicates whether the navigation is a history forward navigation.
| Returns | |
|---|---|
boolean |
True if forward navigation, false otherwise. |
isHistory
public boolean isHistory()
Indicates whether the navigation is a history navigation.
| Returns | |
|---|---|
boolean |
True if history, false otherwise. |
isReload
public boolean isReload()
Indicates whether the navigation is a reload navigation.
| Returns | |
|---|---|
boolean |
True if reload, false otherwise. |
isRestore
public boolean isRestore()
Indicates whether the navigation is a restore navigation after calling restoreState.
| Returns | |
|---|---|
boolean |
True if session restore, false otherwise. |
isSameDocument
public boolean isSameDocument()
Indicates whether the navigation is a same-document navigation.
| Returns | |
|---|---|
boolean |
True if same-document, false otherwise. |
wasInitiatedByPage
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. |