中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
有谁知道如何主动关闭应用
微信扫码分享
import UIAbility from '@ohos.app.ability.UIAbility'; import { BusinessError } from '@ohos.base'; export default class EntryAbility extends UIAbility { onForeground() { try { this.context.terminateSelf((err: BusinessError) => { if (err.code) { // 处理业务逻辑错误 console.error(`terminateSelf failed, code is ${err.code}, message is ${err.message}`); return; } // 执行正常业务 console.info('terminateSelf succeed'); }); } catch (err) { // 捕获同步的参数错误 let code = (err as BusinessError).code; let message = (err as BusinessError).message; console.error(`terminateSelf failed, code is ${code}, message is ${message}`); } } }