mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-01 08:15:37 +08:00
refactor: merge ModuleAppActivity, ModuleAppCompatActivity to ModuleActivity and some tweaks
This commit is contained in:
@@ -146,34 +146,45 @@ Alternatively, if you write a `stub` for the Host App's class, you can register
|
||||
registerModuleAppActivities(TestActivity::class.java)
|
||||
```
|
||||
|
||||
After the registration is complete, extends the `Activity` in the Module App you need to use the Host App to start by `ModuleAppActivity` or `ModuleAppCompatActivity`.
|
||||
After registration is completed, please implement the `ModuleActivity` interface using the `Activity` module in the host-started module.
|
||||
|
||||
These `Activity` now live seamlessly in the Host App without registration.
|
||||
These `Activity` (ies) now live seamlessly in the host without registration.
|
||||
|
||||
We recommend that you create `BaseActivity` as the base class for all modules `Activity`.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
class HostTestActivity : ModuleAppActivity() {
|
||||
abstract class BaseActivity : AppCompatActivity(), ModuleActivity {
|
||||
|
||||
// Set up AppCompat Theme (if currently is [AppCompatActivity])
|
||||
override val moduleTheme get() = R.style.YourAppTheme
|
||||
|
||||
override fun getClassLoader() = delegate.getClassLoader()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
delegate.onCreate(savedInstanceState)
|
||||
super.onCreate(savedInstanceState)
|
||||
// Module App's Resources have been injected automatically
|
||||
// You can directly use xml to load the layout
|
||||
setContentView(R.layout.activity_main)
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
delegate.onConfigurationChanged(newConfig)
|
||||
super.onConfigurationChanged(newConfig)
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
delegate.onRestoreInstanceState(savedInstanceState)
|
||||
super.onRestoreInstanceState(savedInstanceState)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If you need to extends `ModuleAppCompatActivity`, you need to set the AppCompat theme manually.
|
||||
Then inherit the `Activity` you want to implement in `BaseActivity`.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
class HostTestActivity : ModuleAppCompatActivity() {
|
||||
|
||||
// The theme name here is for reference only
|
||||
// Please fill in the theme name already in your Module App
|
||||
override val moduleTheme get() = R.style.Theme_AppCompat
|
||||
class HostTestActivity : BaseActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -200,7 +211,7 @@ If you need to specify a delegated `Activity` to use another Host App's `Activit
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
class HostTestActivity : ModuleAppActivity() {
|
||||
class HostTestActivity : BaseActivity() {
|
||||
|
||||
// Specify an additional proxy Activity class name
|
||||
// Which must also exist in the Host App's AndroidManifest
|
||||
@@ -210,7 +221,7 @@ class HostTestActivity : ModuleAppActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
// Module App's Resources have been injected automatically
|
||||
// You can directly use xml to load the layout
|
||||
setContentView(R. layout. activity_main)
|
||||
setContentView(R.layout.activity_main)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@@ -85,4 +85,10 @@ val instance: Any
|
||||
Now, `YukiHookAPI` no longer limits duplicate Hooks to the same method, you can hook multiple times on the same method.
|
||||
|
||||
`YukiHookAPI` also deprecated the `onAlreadyHooked` method of `hook { ... }`.
|
||||
Now this method will be useless and will not be called back. If necessary, please manually handle the relevant logic of duplicate Hooks.
|
||||
Now this method will be useless and will not be called back. If necessary, please manually handle the relevant logic of duplicate Hooks.
|
||||
|
||||
## Register Module App's Activity Behavior Change
|
||||
|
||||
`YukiHookAPI` Starting with `1.3.0`, the way in which the module `Activity` behavior has changed.
|
||||
|
||||
Please read [Register Module App's Activity](../api/special-features/host-inject#register-module-app-s-activity) for more information.
|
@@ -142,32 +142,45 @@ registerModuleAppActivities(proxy = "com.demo.test.activity.TestActivity")
|
||||
registerModuleAppActivities(TestActivity::class.java)
|
||||
```
|
||||
|
||||
注册完成后,请将你需要使用宿主启动的模块中的 `Activity` 继承于 `ModuleAppActivity` 或 `ModuleAppCompatActivity`。
|
||||
注册完成后,请将你需要使用宿主启动的模块中的 `Activity` 实现 `ModuleActivity` 接口。
|
||||
|
||||
这些 `Activity` 现在无需注册即可无缝存活于宿主中。
|
||||
|
||||
我们推荐你创建 `BaseActivity` 作为所有模块 `Activity` 的基类。
|
||||
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
class HostTestActivity : ModuleAppActivity() {
|
||||
abstract class BaseActivity : AppCompatActivity(), ModuleActivity {
|
||||
|
||||
// 设置 AppCompat 主题 (如果当前是 [AppCompatActivity])
|
||||
override val moduleTheme get() = R.style.YourAppTheme
|
||||
|
||||
override fun getClassLoader() = delegate.getClassLoader()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
delegate.onCreate(savedInstanceState)
|
||||
super.onCreate(savedInstanceState)
|
||||
// 模块资源已被自动注入,可以直接使用 xml 装载布局
|
||||
setContentView(R.layout.activity_main)
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
delegate.onConfigurationChanged(newConfig)
|
||||
super.onConfigurationChanged(newConfig)
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
delegate.onRestoreInstanceState(savedInstanceState)
|
||||
super.onRestoreInstanceState(savedInstanceState)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
若你需要继承于 `ModuleAppCompatActivity`,你需要手动设置 AppCompat 主题。
|
||||
然后将需要实现的 `Activity` 继承于 `BaseActivity`。
|
||||
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
class HostTestActivity : ModuleAppCompatActivity() {
|
||||
|
||||
// 这里的主题名称仅供参考,请填写你模块中已有的主题名称
|
||||
override val moduleTheme get() = R.style.Theme_AppCompat
|
||||
class HostTestActivity : BaseActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -193,7 +206,7 @@ context.startActivity(context, HostTestActivity::class.java)
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
class HostTestActivity : ModuleAppActivity() {
|
||||
class HostTestActivity : BaseActivity() {
|
||||
|
||||
// 指定一个另外的代理 Activity 类名,其也必须存在于宿主的 AndroidManifest 中
|
||||
override val proxyClassName get() = "com.demo.test.activity.OtherActivity"
|
||||
|
@@ -79,4 +79,10 @@ val instance: Any
|
||||
|
||||
`YukiHookAPI` 从 `1.3.0` 版本开始弃用了重复 Hook 的限制,现在,`YukiHookAPI` 不再限制重复 Hook 同一个方法,你可以在同一个方法上多次 Hook。
|
||||
|
||||
`YukiHookAPI` 同时弃用了 `hook { ... }` 的 `onAlreadyHooked` 方法,现在此方法将无作用且不会被回调,如有需要,请手动处理重复 Hook 的相关逻辑。
|
||||
`YukiHookAPI` 同时弃用了 `hook { ... }` 的 `onAlreadyHooked` 方法,现在此方法将无作用且不会被回调,如有需要,请手动处理重复 Hook 的相关逻辑。
|
||||
|
||||
## 注册模块 Activity 行为变更
|
||||
|
||||
`YukiHookAPI` 从 `1.3.0` 版本开始,注册模块 `Activity` 行为的方式发生了变更。
|
||||
|
||||
请阅读 [注册模块 Activity](../api/special-features/host-inject#注册模块-activity) 以了解更多信息。
|
Reference in New Issue
Block a user