HarmonyOS 某页面上某按钮通过api将应用切后台再次唤醒后保持原页面

某页面上某按钮通过api将应用切后台,再次唤醒后保持原页面,效果为点击“不同意, 退出”

当前调用了 UIAbilityContext.terminateSelf api 发现再次打开会重新启动应用

HarmonyOS
2024-12-25 11:08:17
512浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

可以考虑使用最小化窗口而不是关闭应用,示例:

let windowClass: window.Window | undefined = undefined;
try {
  window.getLastWindow(getContext(this), (err: BusinessError, data) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
      return;
    }
    windowClass = data;
    console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
    windowClass?.minimize((err: BusinessError) => {
      const errCode: number = err.code;
      if (errCode) {
        console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`);
        return;
      }
      console.info('Succeeded in minimizing the window.');
    });
  });
} catch (exception) {
  console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
分享
微博
QQ
微信
回复
2024-12-25 14:01:54


相关问题
HarmonyOS 应用后台问题
1034浏览 • 1回复 待解决
HarmonyOS 如何获取,组件的坐标
826浏览 • 1回复 待解决
点击拒接按钮无法再次来电
2448浏览 • 1回复 待解决
HarmonyOS 全局触摸应用后台未触发
521浏览 • 1回复 待解决
HarmonyOS 自定义弹框关闭页面上
721浏览 • 1回复 待解决
HarmonyOS VPN应用如何保持后台运行?
859浏览 • 1回复 待解决
判断类是否实现了接口
1082浏览 • 1回复 待解决
TextField怎么给段文字设置颜色
9668浏览 • 2回复 待解决
如何移除页面上Video组件
2584浏览 • 1回复 待解决