harmony 鸿蒙Ability Subsystem Changelog

  • 2025-06-12
  • 浏览 (27)

Ability Subsystem Changelog

cl.ability.1 API restartApp Changed

Access Level

Public API

Reason for Change

The change is made to prevent malicious applications from restarting themselves when they do not gain focus.

Change Impact

This change is a non-compatible change. An application should call the restartApp API when it is in the focus state. Otherwise, functions will be affected.

Start API Level

12

Change Since

OpenHarmony SDK 5.0.0.31

Adaptation Guide

Call the restartApp API when the application is in the focus state.

Example

import { UIAbility, Want } from '@kit.AbilityKit';

export default class MyAbility extends UIAbility {
  onForeground() {
    let applicationContext = this.context.getApplicationContext();
    let want: Want = {
      bundleName: 'com.example.myapp',
      abilityName: 'EntryAbility'
    };
    try {
      applicationContext.restartApp(want);
    } catch (error) {
      console.error(`restartApp fail, error: ${JSON.stringify(error)}`);
    }
  }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkCompiler Subsystem Changelog

harmony 鸿蒙ArkData Changelog

harmony 鸿蒙Bundle Manager Subsystem Changelog

harmony 鸿蒙Notification Subsystem ChangeLog

harmony 鸿蒙IAM Subsystem ChangeLog

harmony 鸿蒙Window Subsystem Changelog

0  赞