From c5d803eb865e6d817fbbef266ea1490f917dc1ec Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Sun, 25 Sep 2022 00:53:55 +0800 Subject: [PATCH] Update English translation for host-lifecycle documentation --- .../en/api/special-features/host-lifecycle.md | 82 ++++++++++++++++++- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/docs-source/src/en/api/special-features/host-lifecycle.md b/docs-source/src/en/api/special-features/host-lifecycle.md index 6934ccbf..5c1de97f 100644 --- a/docs-source/src/en/api/special-features/host-lifecycle.md +++ b/docs-source/src/en/api/special-features/host-lifecycle.md @@ -1,9 +1,83 @@ -# Host Lifecycle Extension * +# Host Lifecycle Extension -::: warning +> This is an extension of the lifecycle of an automatic hooking Host App. -The current page has not been translated yet. +## Monitor Lifecycle -If necessary, please temporarily switch to the **Simplified Chinese** page, or help us improve the translation of this page. +> Implement the monitoring function by automating the lifecycle method of the Host App. + +We need to listen to the startup and lifecycle methods of the Host App's `Application`, just use the following methods. + +> The following example + +```kotlin +loadApp(name = "com.example.demo") { + // Register lifecycle listeners + onAppLifecycle { + // You can implement lifecycle method listeners in Application here + attachBaseContext { baseContext, hasCalledSuper -> + // Determine whether + // The super.attachBaseContext(base) method has been executed by judging hasCalledSuper + // ... + } + onCreate { + // Get the current Application instance through this + // ... + } + onTerminate { + // Get the current Application instance through this + // ... + } + onLowMemory { + // Get the current Application instance through this + // ... + } + onTrimMemory { self, level -> + // Here you can judge whether the app has switched to the background + if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { + // ... + } + // ... + } + onConfigurationChanged { self, config -> + // ... + } + } +} +``` + +::: tip + +For more functions, please refer to [AppLifecycle](../public/com/highcapable/yukihookapi/hook/param/PackageParam#applifecycle-class). + +::: + +## Register System Broadcast + +> Register system broadcast through the `Application.onCreate` method to monitor system broadcast. + +We can also register system broadcast in the Host App's `Application`. + +> The following example + +```kotlin +loadApp(name = "com.example.demo") { + // Register lifecycle listeners + onAppLifecycle { + // Broadcast monitoring when the registered user is unlocked + registerReceiver(Intent.ACTION_USER_PRESENT) { context, intent -> + // ... + } + // Register multiple broadcast listeners, will call back multiple times at the same time + registerReceiver(Intent.ACTION_PACKAGE_CHANGED, Intent.ACTION_TIME_TICK) { context, intent -> + // ... + } + } +} +``` + +::: tip + +For more functions, please refer to [AppLifecycle](../public/com/highcapable/yukihookapi/hook/param/PackageParam#applifecycle-class). ::: \ No newline at end of file