当前位置: 首页 > news >正文

鸿蒙-任务栏右击退出 或 UIAbility窗口关闭,怎么弹框拦截

onPrepareToTerminate 需要配置权限 ohos.permission.PREPARE_APP_TERMINATE
参考链接:文档中心import { emitter } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';
import { TipsDialog } from '@kit.ArkUI';// entryAbility.ets 在你的uiability中添加如下生命周期
onPrepareToTerminate() {// 开发者定义预关闭动作emitter.emit("windowWillDestroy")emitter.on("close",(data)=>{this.context.terminateSelf();})return true; // 已定义预关闭操作后,返回true表示UIAbility取消关闭
}// Index.ets:
@Entry
@Component
struct Page {@State message: string = 'Hello World';dialogControllerImage: CustomDialogController = new CustomDialogController({builder: TipsDialog({content: '想要关闭这个APP嘛?',primaryButton: {value: '取消',action: () => {console.info('Callback when the first button is clicked')},},secondaryButton: {value: '退出',role: ButtonRole.ERROR,action: () => {emitter.emit("close");console.info('Callback when the second button is clicked')}},onCheckedChange: () => {console.info('Callback when the checkbox is clicked')}}),})onPageShow(): void {emitter.on("windowWillDestroy", () => {let ablityContext = getContext() as common.UIAbilityContext // 这行没用到ablityContext.showAbility()    // 这行没用到console.log("yes")this.dialogControllerImage.open()})}build() {RelativeContainer() {Text(this.message).id('PageHelloWorld').fontSize(50).fontWeight(FontWeight.Bold).alignRules({center: { anchor: '__container__', align: VerticalAlign.Center },middle: { anchor: '__container__', align: HorizontalAlign.Center }})}.height('100%').width('100%')}
}
http://www.lryc.cn/news/469583.html

相关文章:

  • 【C++进阶篇】——STL的简介
  • 信息安全工程师(70)网络攻击陷阱技术与应用
  • Web保存状态的手段(Session的使用)
  • 第五十四章 安全元素的详细信息 - DerivedKeyToken 详情
  • kafka 的高可用机制是什么?
  • 4.1.3 网站通信技术
  • Java-图书管理系统
  • python如何通过json以及pickle读写保存数据
  • 【SPIE出版,EI检索稳定】2024年人机交互与虚拟现实国际会议(HCIVR 2024,11月15-17日)
  • Linux vim编辑器
  • 普推知产:申请商标名称从4字改成3字下了初审!
  • Flink 状态精准一次性特性
  • 算法笔记day08
  • 在Selenium中有哪些元素对象操作方法?( ̄﹃ ̄)
  • sqli-labs靶场安装以及刷题记录-docker
  • 谷歌仓库管理工具repo
  • C#的自定义Tip窗体 - 开源研究系列文章
  • 目前最新 Reflector V11.1.0.2067版本 .NET 反编译软件
  • 软考:CORBA架构
  • qt QSaveFile详解
  • 【Linux】线程池详解及其基本架构与单例模式实现
  • 运输层知识点汇总3
  • 浔川社团官方联合会提前入驻
  • 比例数据可视化(Python实现板块层级图绘制)——Instacart Market Basket Analysis
  • C++研发笔记8——C语言程序设计初阶学习笔记6
  • 0softmax和背后的最大熵(极大似然法)
  • 6,000 个网站上的假 WordPress 插件提示用户安装恶意软件
  • 最新Compose环境版本
  • 流媒体协议.之(RTP,RTCP,RTSP,RTMP,HTTP)(一)
  • 【智能大数据分析 | 实验四】Spark实验:Spark Streaming