harmony 鸿蒙API Switching Overview

  • 2023-02-03
  • 浏览 (686)

API Switching Overview

Due to the differences in the thread model and process model, certain APIs can be used only in the FA model. They are marked with FAModelOnly in the SDK. When switching an application from the FA model to the stage model, replace the APIs marked with FAModelOnly in the application with the APIs supported in the stage model. This topic uses the switching of startAbility() as an example.

api-switch-overview

  • Sample code of startAbility() in the FA model:
  import fa from '@ohos.ability.featureAbility';
  import { BusinessError } from '@ohos.base';

  fa.startAbility({
    "want": {
      bundleName: "com.example.myapplication",
      abilityName: "com.example.myapplication.EntryAbility"
    }
  }).then((data) => {
    console.info('startAbility success');
  }).catch((error: BusinessError) => {
    console.error('startAbility failed.');
  })
  • Sample code of startAbility() in the stage model:
  import Want from '@ohos.app.ability.Want';

  // Context is a member of the ability object and is required for invoking inside a non-ability object.
  // Pass in the Context object.
  let wantInfo: Want = {
    bundleName: "com.example.myapplication",
    abilityName: "EntryAbility"
  };
  this.context.startAbility(wantInfo).then(() => {
    console.info('startAbility success.');
  }).catch((error: BusinessError) => {
    console.error('startAbility failed.');
  })

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Application Models

harmony 鸿蒙Using Explicit Want to Start an Application Component

harmony 鸿蒙Using Implicit Want to Open a Website

harmony 鸿蒙AbilityStage Component Container

harmony 鸿蒙Accessing a DataAbility

harmony 鸿蒙Accessing a DataShareExtensionAbility from the FA Model

harmony 鸿蒙AccessibilityExtensionAbility

harmony 鸿蒙Common action and entities Values

harmony 鸿蒙Switching of app and deviceConfig

harmony 鸿蒙Application- or Component-Level Configuration (FA Model)

0  赞