This article mainly introduces the function, usage method and precautions of the IMiniAppEventObserver interface
1. Introduce
The IMiniAppEventObserver interface is used to listen for lifecycle events of Miniapp
public interface IMiniAppEventObserver {
void onMiniAppStart(Map<String, Object> params);
void onMiniAppClose(Map<String, Object> params);
void onMiniAppShow(Map<String, Object> params);
void onMiniAppHide(Map<String, Object> params);
}1.1 onMiniAppStart
Triggered by the Activity onCreate(...) method of the Miniapp, executed on the main thread
params includes the following:
Key "app_code":The 'App Code' obtained by users when creating an app on an open platform
Key "mini_app_id": Mini app ID
Key "mini_app_version":Mini app version
Key "timestamp":The timestamp of the event occurrence
1.2 onMiniAppShow
Triggered by the Activity onResume() method of the Miniapp, executed on the main thread
params includes the following:
Key "app_code":The 'App Code' obtained by users when creating an app on an open platform
Key "mini_app_id": Mini app ID
Key "mini_app_version":Mini app version
Key "timestamp":The timestamp of the event occurrence
1.3 onMiniAppHide
Triggered by the Activity onPause() method of the Miniapp, executed on the main thread
params includes the following:
Key "app_code":The 'App Code' obtained by users when creating an app on an open platform
Key "mini_app_id": Mini app ID
Key "mini_app_version":Mini app version
Key "timestamp":The timestamp of the event occurrence
1.4 onMiniAppClose
Triggered by the Activity onDestory() method of the Miniapp, executed on the main thread
params includes the following:
Key "app_code":The 'App Code' obtained by users when creating an app on an open platform
Key "mini_app_id": Mini app ID
Key "mini_app_version":Mini app version
Key "timestamp":The timestamp of the event occurrence
2. Register & Unregister
2.1 Create Observer object
private IMiniAppEventObserver mObserver = new IMiniAppEventObserver() {
@Override
public void onMiniAppStart(Map<String, Object> params) {
}
@Override
public void onMiniAppClose(Map<String, Object> params) {
}
@Override
public void onMiniAppShow(Map<String, Object> params) {
}
@Override
public void onMiniAppHide(Map<String, Object> params) {
}
};2.2 Register
private void registerObserver() {
PluginEnv.getInstance().getContainerContext().getLifeCycleService()
.registerMiniAppObserver(mObserver);
}
2.3 Unregister
private void unregisterObserver() {
PluginEnv.getInstance().getContainerContext().getLifeCycleService()
.unregisterMiniAppObserver(mObserver);
}3. Usage Case (Data Reporting)
[Plugin Development] MiniApp Data Analysis Plugin Development