提交 94f8e2c1 编写于 作者: X xinking129

modify code

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 2c001841
......@@ -16,8 +16,7 @@ import hilog from '@ohos.hilog';
import Ability from '@ohos.app.ability.UIAbility';
import type Window from '@ohos.window';
import commonEvent from '@ohos.commonEvent';
const ONE_SECOND = 1000;
const FIVE_HUNDRED_MILLISECOND = 500;
const VALID_STATE = 1;
const INVALID_STATE = -1;
const TAG = 'StateChangeTestTAG';
......@@ -33,12 +32,10 @@ let applicationStateChangeCallbackFir = {
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationForeground');
commonEventData.parameters.commonStateArr[0] = VALID_STATE;
setTimeout(() => {
console.info('Enter onApplicationForeground publish!');
commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err));
});
}, ONE_SECOND);
console.info('Enter onApplicationForeground publish!');
commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err));
});
},
onApplicationBackground() {
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationBackground');
......@@ -61,15 +58,11 @@ let applicationStateChangeCallbackSec = {
console.log(TAG, 'applicationStateChangeCallbackSec onApplicationBackground');
commonEventData.parameters.commonStateArr[3] = VALID_STATE;
if (globalThis.want.action === 'doubleNeedBackGroundOff') {
setTimeout(() => {
globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackSec);
}, FIVE_HUNDRED_MILLISECOND);
globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackSec);
}
else if (globalThis.want.action === 'DoubleRegisterOff') {
setTimeout(() => {
console.info('entered DoubleRegisterOff');
globalThis.applicationContext.off('applicationStateChange');
}, FIVE_HUNDRED_MILLISECOND);
console.info('entered DoubleRegisterOff');
globalThis.applicationContext.off('applicationStateChange');
}
}
}
......@@ -132,11 +125,9 @@ export default class EntryAbility extends Ability {
onForeGroundTAG++;
if (onForeGroundTAG === VALID_STATE && (globalThis.want.action === 'NeedBackGroundOff' || globalThis.want.action === 'MultiAppRegister'
|| globalThis.want.action === 'DoubleRegisterOff')) {
setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => {
commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err));
})
}, 2000);
})
}
}
......
......@@ -17,8 +17,6 @@ import Ability from '@ohos.app.ability.UIAbility';
import type Window from '@ohos.window';
import commonEvent from '@ohos.commonEvent';
const ONE_SECOND = 1000;
const THREE_SECOND = 3000;
const VALID_STATE = 1;
const INVALID_STATE = -1;
const TAG = 'getRunningProcess';
......@@ -34,13 +32,11 @@ let applicationStateChangeCallbackFir = {
},
onApplicationBackground() {
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationBackground');
setTimeout(() => {
console.info('Enter onApplicationForeground publish!');
commonEventData.parameters.commonStateArr = VALID_STATE;
commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err));
});
}, ONE_SECOND);
console.info('Enter onApplicationForeground publish!');
commonEventData.parameters.commonStateArr = VALID_STATE;
commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err));
});
}
};
let foregroundTAG = INVALID_STATE;
......@@ -89,11 +85,9 @@ export default class EntryAbility extends Ability {
// Ability has brought to foreground
foregroundTAG++
if (foregroundTAG === VALID_STATE) {
setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => {
commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err));
})
}, THREE_SECOND)
})
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
......
......@@ -58,11 +58,9 @@ export default class EntryAbility1 extends Ability {
// Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
setTimeout(() => {
globalThis.abilityContext2.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
});
}, 3000);
globalThis.abilityContext2.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
onBackground() {
......
......@@ -73,11 +73,9 @@ export default class EntryAbility extends Ability {
// Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
setTimeout(() => {
globalThis.abilityContext.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
});
}, 3000);
globalThis.abilityContext.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
onBackground() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册