Update xposed-channel documentation

This commit is contained in:
2023-01-03 20:41:27 +08:00
parent 1ec5a02db2
commit 1d42406ad1
2 changed files with 118 additions and 2 deletions

View File

@@ -176,7 +176,7 @@ The `key` of callback event C is not duplicated with others.
Although the `key` of callback event D is the same as that of callback event C, their Host Apps are different, so they can exist at the same time.
Callback event E is in another Activity, although the `key` of callback event F and callback event E is the same, but they are not the same Host App, so they can exist at the same time.
Callback event E is in another **Activity**, although the `key` of callback event F and callback event E is the same, but they are not the same Host App, so they can exist at the same time.
In summary, the final callback events B, C, D, E, and F can all be created successfully.
@@ -198,6 +198,65 @@ If you want to use **dataChannel** in **Fragment**, use **activity?.dataChannel(
:::
If you want to manually set the response priority (condition) of each callback event in the same **Activity**, you can use `ChannelPriority`.
For example, if you are using one **Activity** binding multiple **Fragment** cases, this will be able to solve this problem.
> The following example
```kotlin
open class BaseFragment : Fragment() {
/** Identify that the current Fragment is in the onResume lifecycle */
var isResume = false
override fun onResume() {
super. onResume()
isResume = true
}
override fun onPause() {
super. onPause()
isResume = false
}
override fun onStop() {
super. onStop()
isResume = false
}
}
class FragmentA : BaseFragment() {
// Omit part of initialization code
//...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// Use the custom isResume combined with the isVisible condition
// To judge that the current Fragment is in the displayed state
activity?.dataChannel(packageName = "com.example.demo1")
?.wait(key = "test_key", ChannelPriority { isResume && isVisible }) {
// Your code here.
}
}
}
class FragmentB : BaseFragment() {
// Omit part of initialization code
//...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// Use the custom isResume combined with the isVisible condition
// To judge that the current Fragment is in the displayed state
activity?.dataChannel(packageName = "com.example.demo2")
?.wait(key = "test_key", ChannelPriority { isResume && isVisible }) {
// Your code here.
}
}
}
```
## Security Instructions
In the Module environment, you can only receive the communication data sent by <u>**the Host App of the specified package name**</u> and can only send to <u>**the Host App of the specified package name**</u>, except for System Framework.

View File

@@ -170,7 +170,7 @@ class OtherActivity : AppCompatActivity() {
回调事件 C 的 `key` 不与其它重复,虽然回调事件 D 的 `key` 与回调事件 C 相同,但是它们的宿主不同,所以可以同时存在。
回调事件 E 在另一个 Activity 中,回调事件 F 与回调事件 E 的 `key` 虽然相同,但它们也不是同一个宿主,所以可以同时存在。
回调事件 E 在另一个 **Activity** 中,回调事件 F 与回调事件 E 的 `key` 虽然相同,但它们也不是同一个宿主,所以可以同时存在。
综上所述,最终回调事件 B、C、D、E、F 都可被创建成功。
@@ -192,6 +192,63 @@ class OtherActivity : AppCompatActivity() {
:::
如果你希望在同一个 **Activity** 中手动设置每个回调事件的响应优先级 (条件),你可以使用 `ChannelPriority`
例如,你正在使用一个 **Activity** 绑定多个 **Fragment** 的情况,这将能够解决这个问题。
> 示例如下
```kotlin
open class BaseFragment : Fragment() {
/** 标识当前 Fragment 处于 onResume 生命周期 */
var isResume = false
override fun onResume() {
super.onResume()
isResume = true
}
override fun onPause() {
super.onPause()
isResume = false
}
override fun onStop() {
super.onStop()
isResume = false
}
}
class FragmentA : BaseFragment() {
// 省略部分装载代码
// ...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// 使用自定义的 isResume 结合 isVisible 条件判断当前 Fragment 正处于显示状态
activity?.dataChannel(packageName = "com.example.demo1")
?.wait(key = "test_key", ChannelPriority { isResume && isVisible }) {
// Your code here.
}
}
}
class FragmentB : BaseFragment() {
// 省略部分装载代码
// ...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// 使用自定义的 isResume 结合 isVisible 条件判断当前 Fragment 正处于显示状态
activity?.dataChannel(packageName = "com.example.demo2")
?.wait(key = "test_key", ChannelPriority { isResume && isVisible }) {
// Your code here.
}
}
}
```
## 安全性说明
在模块环境中,你只能接收<u>**指定包名的宿主**</u>发送的通讯数据且只能发送给<u>**指定包名的宿主**</u>,系统框架除外。