• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# API Switching Overview
2
3
4Due 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.
5
6![api-switch-overview](figures/api-switch-overview.png)
7
8
9
10- Sample code of **startAbility()** in the FA model:
11
12  ```ts
13  import fa from '@ohos.ability.featureAbility';
14  import { BusinessError } from '@ohos.base';
15
16  fa.startAbility({
17    "want": {
18      bundleName: "com.example.myapplication",
19      abilityName: "com.example.myapplication.EntryAbility"
20    }
21  }).then((data) => {
22    console.info('startAbility success');
23  }).catch((error: BusinessError) => {
24    console.error('startAbility failed.');
25  })
26  ```
27
28- Sample code of **startAbility()** in the stage model:
29
30  ```ts
31  import Want from '@ohos.app.ability.Want';
32
33  // Context is a member of the ability object and is required for invoking inside a non-ability object.
34  // Pass in the Context object.
35  let wantInfo: Want = {
36    bundleName: "com.example.myapplication",
37    abilityName: "EntryAbility"
38  };
39  this.context.startAbility(wantInfo).then(() => {
40    console.info('startAbility success.');
41  }).catch((error: BusinessError) => {
42    console.error('startAbility failed.');
43  })
44  ```
45