mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 01:35:17 +08:00
Update English translation for host-lifecycle documentation
This commit is contained in:
@@ -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).
|
||||
|
||||
:::
|
Reference in New Issue
Block a user