• 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 (marked with **FAModelOnly** in the SDK) can be used only in the FA model. 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  let parameter = {
15    "want": {
16      bundleName: "com.example.myapplication",
17      abilityName: "com.example.myapplication.EntryAbility"
18    }
19  }
20  fa.startAbility(parameter).then((data) => {
21    console.info('startAbility success');
22  }).catch((error) => {
23    console.error('startAbility failed.');
24  })
25  ```
26
27- Sample code of **startAbility()** in the stage model:
28
29  ```ts
30  // context is a member of the ability object and is required for invoking inside a non-ability object.
31  // Pass in the Context object.
32  let wantInfo = {
33    bundleName: "com.example.myapplication",
34    abilityName: "EntryAbility"
35  };
36  this.context.startAbility(wantInfo).then((data) => {
37    console.info('startAbility success.');
38  }).catch((error) => {
39    console.error('startAbility failed.');
40  })
41  ```
42