鸿蒙 如何退出 APP

terminateSelf() 停止Ability自身

在EntryAbility中这么使用

复制代码
this.context.terminateSelf()

在Pages页面中这么使用

复制代码
import { common } from '@kit.AbilityKit'
(getContext(this) as common.UIAbilityContext)?.terminateSelf()

也可以直接封装:

复制代码
import common from '@ohos.app.ability.common'

let context = getContext(this) as common.UIAbilityContext

export default class AppUtil {
  public static out() {
    context.terminateSelf()
  }
}

最后调用: AppUtil.out() 搞定🤝

相关推荐
maaath36 分钟前
【maaath】Flutter 跨平台日历日程应用开发实战
flutter·华为·harmonyos
LeesonWong2 小时前
架构困境与四层结构化设计
harmonyos
梦想不只是梦与想3 小时前
鸿蒙 应用市场更新功能:版本检测与更新提醒
harmonyos·鸿蒙·版本更新
xmdy58663 小时前
Flutter+开源鸿蒙实战|智安盾电商溯源平台Day2 首页+核心入口UI开发(鸿蒙多端适配)
flutter·开源·harmonyos
jiejiejiejie_3 小时前
Flutter for OpenHarmony 萌系 UI 实战合集:骨架屏 + 引导页一站式指南
flutter·ui·华为
nashane7 小时前
HarmonyOS 6学习:HAR包与HSP包的选择与优化指南
学习·华为·harmonyos·harmonyos 5
全栈若城7 小时前
自定义 TabBar 实战:浮动标签栏与舵式标签栏
harmonyos·harmonyos6·三方库开发
maaath7 小时前
【maaath】Flutter for OpenHarmony 学习答题应用实战开发
学习·flutter·华为·harmonyos
李游Leo7 小时前
别再拼 JSON 了:HarmonyOS UDMF 跨应用数据流转实践
harmonyos
maaath8 小时前
【maaath】Flutter for OpenHarmony 实战:记账理财应用开发指南
flutter·华为·harmonyos