harmony 鸿蒙@ohos.application.AbilityStage (AbilityStage)

  • 2022-08-09
  • 浏览 (954)

@ohos.application.AbilityStage (AbilityStage)

AbilityStage is a runtime class for HAP files.

The AbilityStage module notifies you of when you can perform HAP initialization such as resource pre-loading and thread creation during the HAP loading.

NOTE

The APIs of this module are supported and deprecated since API version 9. You are advised to use @ohos.app.ability.AbilityStage instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. The APIs of this module can be used only in the stage model.

Modules to Import

import AbilityStage from '@ohos.application.AbilityStage';

AbilityStage.onCreate

onCreate(): void

Called when the application is created.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Example

  class MyAbilityStage extends AbilityStage {
      onCreate() {
          console.log("MyAbilityStage.onCreate is called")
      }
  }

AbilityStage.onAcceptWant

onAcceptWant(want: Want): string;

Called when a UIAbility is started.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
want Want Yes Want information about the target UIAbility, such as the ability name and bundle name.

Return value

Type Description
string Returns a UIAbility ID. If this UIAbility has been started, no new instance is created and the UIAbility is placed at the top of the stack. Otherwise, a new instance is created and started.

Example

  class MyAbilityStage extends AbilityStage {
      onAcceptWant(want) {
          console.log("MyAbilityStage.onAcceptWant called");
          return "com.example.test";
      }
  }

AbilityStage.onConfigurationUpdated

onConfigurationUpdated(config: Configuration): void;

Called when the global configuration is updated.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
config Configuration Yes Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.

Example

  class MyAbilityStage extends AbilityStage {
      onConfigurationUpdated(config) {
          console.log('onConfigurationUpdated, language:' + config.language);
      }
  }

AbilityStage.onMemoryLevel

onMemoryLevel(level: AbilityConstant.MemoryLevel): void;

Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible.

System capability: SystemCapability.Ability.AbilityRuntime.AbilityCore

Parameters

Name Type Mandatory Description
level AbilityConstant.MemoryLevel Yes Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.

Example

  class MyAbilityStage extends AbilityStage {
    onMemoryLevel(level) {
        console.log('onMemoryLevel, level:' + JSON.stringify(level));
    } 
  }

AbilityStage.context

context: AbilityStageContext;

Defines the Context object of AbilityStage.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Name Type Description
context AbilityStageContext Context object of AbilityStage.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

harmony 鸿蒙@ohos.WorkSchedulerExtensionAbility (Work Scheduler Callbacks)

0  赞