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

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

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

HarmonyOS
2024-12-25 11:08:17
浏览
收藏 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}`);
}
分享
微博
QQ
微信
回复
2024-12-25 14:01:54
相关问题
HarmonyOS 应用后台问题
554浏览 • 1回复 待解决
HarmonyOS 如何获取,组件的坐标
311浏览 • 1回复 待解决
点击拒接按钮无法再次来电
2106浏览 • 1回复 待解决
HarmonyOS 全局触摸应用后台未触发
99浏览 • 1回复 待解决
HarmonyOS VPN应用如何保持后台运行?
192浏览 • 1回复 待解决
HarmonyOS 自定义弹框关闭页面上
189浏览 • 1回复 待解决
判断类是否实现了接口
653浏览 • 1回复 待解决
TextField怎么给段文字设置颜色
9115浏览 • 2回复 待解决
如何移除页面上Video组件
1961浏览 • 1回复 待解决