Listen for the page lifecycle event

When opening a page in SDK, similar with the Activity lifecycle, SDK has its own lifecycle. If you want to do some work in the page lifecycle, you can implement the GriverPageHelperEvent that contains the page lifecycle events.

Procedures

To listen for the page lifecycle events, complete the following steps:

Step 1: Implement the GriverPageHelperEvent interface

Implement GriverPageHelperEvent and write code in the required methods according to your business logic. See the following example for how to implement this interface.

copy
class DemoGriverPageHelperEvent : GriverPageHelperEvent {
    override fun onPageStarted(page: Page, url: String) {
    }

    override fun onPageFinished(page: Page, url: String) {
    }

    override fun onPagePause(page: Page) {
    }

    override fun onPageResume(page: Page) {
    }

    override fun onProgressChanged(page: Page, url: String, newProgress: Int) {
    }

    override fun onPageBacked(page: Page) {
    }

    override fun onPageExit(page: Page) {
    }

    override fun onPageDestroy(page: Page) {
    }

    override fun onInitialized() {
    }

    override fun onFinalized() {
    }
}

Step 2: Register the DemoGriverPageHelperEvent class

Call the registerEventHandler API to register the page helper event after initializing the SDK.

Sample code:

copy
Griver.registerEventHandler(
    GriverEventManifest(
        DemoGriverPageHelperEvent::class.java.name,
        Arrays.asList(GriverPageHelperEvent::class.java.name), Page::class.java
    )
)

Structures

GriverPageHelperEvent interface

The definition of the GriverPageHelperEvent interface is shown in the following code:

copy
interface GriverPageHelperEvent : GriverEvent {

    fun onPageStarted(page: Page?, url: String?)

    fun onPageFinished(page: Page?, url: String?)

    fun onPagePause(page: Page?)

    fun onPageResume(page: Page?)

    fun onProgressChanged(page: Page?, url: String?, newProgress: Int)

    fun onPageBacked(page: Page?)

    fun onPageExit(page: Page?)

    fun onPageDestroy(page: Page?)
}

Based on the definition, this interface provides the following methods:

Method Name

Description

onPageStarted

The "page started" event is triggered after the WebView finishes loading the page (corresponding to the following onPageFinished event).

It is related to the onPageStarted callback of the WebViewClient.

onPageFinished

You can implement the onPageFinished method to listen for the "page loading finished" event.

It is related to the onPageFinished callback of WebViewClient.

onPagePause

When page goes to the background, the Activity triggers the "page pause" event. Subsequently, the page triggers the pause event. You can implement the onPagePause method to listen for the native page pause event.

onPageResume

Corresponding to the pause event, the "page resume" event is triggered when the Activity resumes. You can implement the onPageResume method to listen for the native page resume event.

onProgressChanged

If you want to know the progress of loading, you can implement the onProgressChanged method.

It is related to the onProgressChanged callback of WebViewClient.

onPageBacked

If you want to listen for the "page back" event, you can implement the onPageBacked method. It contains the back event that is triggered by clicking the back button or by the physical back event.

onPageExit

If you want to listen for the "page exit" event, you can implement the onPageExit method.

onPageDestroy

If you want to listen for the "page destroy" event , you can implement the onPageDestroy method.