提交 a8354145 编写于 作者: M mahaifeng

[activity-callback]修改示例

上级 dc6dd04a
...@@ -94,7 +94,9 @@ import { ...@@ -94,7 +94,9 @@ import {
UTSActivityWindowCallback, UTSActivityWindowCallback,
UTSActivityCallback, UTSActivityCallback,
UTSActivityComponentCallback, UTSActivityComponentCallback,
onCallbackChange onCallbackChange,
registerCallbacks,
unRegisterCallbacks
} from '@/uni_modules/uts-syntaxcase/utssdk/app-android/index.uts' } from '@/uni_modules/uts-syntaxcase/utssdk/app-android/index.uts'
// #endif // #endif
...@@ -321,22 +323,10 @@ export default { ...@@ -321,22 +323,10 @@ export default {
let nextLineFlag = that.cbText + '\n' let nextLineFlag = that.cbText + '\n'
that.cbText = nextLineFlag that.cbText = nextLineFlag
}) })
let reg1= UTSAndroid.registerActivityCallback( new UTSAcvitiyLifeCycleCallback()) registerCallbacks()
let reg2=UTSAndroid.registerActivityCallback(new UTSActivityWindowCallback())
let reg3=UTSAndroid.registerActivityCallback(new UTSAcvitiyKeyEventCallback())
let reg4= UTSAndroid.registerActivityCallback(new UTSActivityCallback())
let reg5= UTSAndroid.registerActivityCallback(new UTSActivityComponentCallback())
this.callbackIds.push(reg1)
this.callbackIds.push(reg2)
this.callbackIds.push(reg3)
this.callbackIds.push(reg4)
this.callbackIds.push(reg5)
}, },
unRegActivityCallback(){ unRegActivityCallback(){
this.callbackIds.forEach((value)=>{ unRegisterCallbacks()
console.log(value)
UTSAndroid.unRegisterActivityCallback(value)
})
} }
// #endif // #endif
......
...@@ -6,11 +6,30 @@ import KeyboardShortcutGroup from 'android.view.KeyboardShortcutGroup'; ...@@ -6,11 +6,30 @@ import KeyboardShortcutGroup from 'android.view.KeyboardShortcutGroup';
import WindowManager from 'android.view.WindowManager'; import WindowManager from 'android.view.WindowManager';
import ActionMode from 'android.view.ActionMode'; import ActionMode from 'android.view.ActionMode';
// export let onCallBackChange: (event: string) => void = (res) => {}; // export let onCallBackChange: (event: string) => void = (res) => {};
let callback : (eventLog : string) => void= (res) => {}; let callback : (eventLog : string) => void = (res) => { };
let callbackIds : string[] = [];
export function onCallbackChange(fn : (eventLog : string) => void) { export function onCallbackChange(fn : (eventLog : string) => void) {
callback = fn callback = fn
} }
export function registerCallbacks() {
let reg1 = UTSAndroid.registerActivityCallback(new UTSAcvitiyLifeCycleCallback())
let reg2 = UTSAndroid.registerActivityCallback(new UTSActivityWindowCallback())
let reg3 = UTSAndroid.registerActivityCallback(new UTSAcvitiyKeyEventCallback())
let reg4 = UTSAndroid.registerActivityCallback(new UTSActivityCallback())
let reg5 = UTSAndroid.registerActivityCallback(new UTSActivityComponentCallback())
callbackIds.push(reg1)
callbackIds.push(reg2)
callbackIds.push(reg3)
callbackIds.push(reg4)
callbackIds.push(reg5)
}
export function unRegisterCallbacks() {
callbackIds.forEach((value) => {
console.log(value)
UTSAndroid.unRegisterActivityCallback(value)
})
}
export class UTSAcvitiyLifeCycleCallback extends UniActivityLifeCycleCallback { export class UTSAcvitiyLifeCycleCallback extends UniActivityLifeCycleCallback {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册