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:
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.
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:
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 |
Binds the current | |
Called after the | |
onResume | Called after the |
Called after the | |
Called after the | |
onPause | Called after the |
onStop | Called after the |
onDestroy | Called after the |
finish | Called after the |
Called after the | |
dispatchTouchEvent | Called befor the |
bindActivity method
Parameter | Data type | Required | Description |
activity |
| No | The |
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 |
onNewIntent method
Parameter | Data type | Required | Description |
intent | Intent | Yes | The parameter of |
onActivityResult method
Parameter | Data type | Required | Description |
requestCode | Int | Yes | The request code of |
resultCode | Int | Yes | The result code of |
data | Intent | Yes | The data of |
onRequestPermissionsResult method
Parameter | Data type | Required | Description |
requestCode | Int | Yes | The request code of |
permissions | Array | Yes | The permissions of |
grantResults | IntArray | Yes | The grant results of |
dispatchTouchEvent method
Parameter | Data type | Required | Description |
ev | MotionEvent | Yes | The parameter of |