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.
-
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.'); })