ActivityHelperExtension

IAPMiniProgram SDK provides the ability to monitor the lifecycle methods of the Activity object where the Mini Program is located, so that the Super App can perform specified operations. Follow this topic to monitor the lifecycle methods of the Activity object by implementing the specific interface of IAPMiniProgram SDK.

Procedures

Step 1. Implement the ActivityHelperExtension interface

Implement the ActivityHelperExtension interface and write code in the required methods according to your business logic.

Code sample as follows:

copy
class CustomActivityHelperExtensionImpl : ActivityHelperExtension {
    override fun bindActivity(activity: Activity?) {
    }

    override fun onCreate(savedInstanceState: Bundle?) {
    }

    override fun onResume() {
    }

    override fun onNewIntent(intent: Intent?) {
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    }

    override fun onPause() {
    }

    override fun onStop() {
    }

    override fun onDestroy() {
    }

    override fun finish() {
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
    }

    override fun dispatchTouchEvent(ev: MotionEvent?) {
    }
}

Step 2: Register the CustomActivityHelperExtensionImpl class

Refer to the following sample code and call the registerExtension interface to register the CustomActivityHelperExtensionImpl class after initializing the SDK.

copy
IAPConnect.init(application, initConfig, object : InitCallback() {
    fun onSuccess() {
        //···
        Griver.registerExtension(
            GriverExtensionManifest(
                ActivityHelperExtension::class.java,
                CustomActivityHelperExtensionImpl()
            )
        )
    }
})

Structures

ActivityHelperExtension interface

The definition of the ActivityHelperExtension interface is shown in the following codes:

copy
interface ActivityHelperExtension : GriverExtension {
    
    fun bindActivity(activity: Activity?)

    fun onCreate(savedInstanceState: Bundle?)

    fun onResume()

    fun onNewIntent(intent: Intent?)
    
    fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)

    fun onPause()

    fun onStop()

    fun onDestroy()

    fun finish()

    fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<String?>,
        grantResults: IntArray
    )

    fun dispatchTouchEvent(ev: MotionEvent?)
}

Methods

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

Method

Description

bindActivity

Binds the current Activity. Save this Activity to use in other ActivityHelperExtension methods.

onCreate

Called after the Activity#onCreate(Bundle) is invoked.

onResume

Called after the Activity#onResumse() is invoked.

onNewIntent

Called after the Activity#onNewIntent(Intent) is invoked.

onActivityResult

Called after the Activity#onActivityResult(int, int, Intent) is invoked.

onPause

Called after the Activity#onPause() is invoked.

onStop

Called after the Activity#onStop() is invoked.

onDestroy

Called after the Activity#onDestroy() is invoked.

finish

Called after the Activity#finish() is invoked.

onRequestPermissionsResult

Called after the Activity#onRequestPermissionsResult(int, String[], int[]) is invoked.

dispatchTouchEvent

Called befor the Activity#dispatchTouchEvent(MotionEvent) is invoked.

bindActivity method

Parameter

Data type

Required

Description

activity

Activity

No

The Activity object where the current mini program is located.

onCreate method

Parameter

Data type

Required

Description

savedInstanceState

Bundle

No

If the activity is being re-initialized after previously being shutdown, then this Bundle contains the data. It is recently supplied in Activity#onSaveInstanceState(Bundle).

onNewIntent method

Parameter

Data type

Required

Description

intent

Intent

Yes

The parameter of Activity#onNewIntent(Intent).

onActivityResult method

Parameter

Data type

Required

Description

requestCode

Int

Yes

The request code of Activity#onActivityResult(int, int, Intent).

resultCode

Int

Yes

The result code of Activity#onActivityResult(int, int, Intent).

data

Intent

Yes

The data of Activity#onActivityResult(int, int, Intent).

onRequestPermissionsResult method

Parameter

Data type

Required

Description

requestCode

Int

Yes

The request code of Activity#onRequestPermissionsResult(int, String[], int[]).

permissions

Array

Yes

The permissions of Activity#onRequestPermissionsResult(int, String[], int[]).

grantResults

IntArray

Yes

The grant results of Activity#onRequestPermissionsResult(int, String[], int[]).

dispatchTouchEvent method

Parameter

Data type

Required

Description

ev

MotionEvent

Yes

The parameter of Activity#dispatchTouchEvent(MotionEvent).