1e41f4b71Sopenharmony_ci# PageAbility Switching
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThe PageAbility component in the FA model corresponds to the UIAbility component in the stage model. To switch a PageAbility to a UIAbility, perform the following operations:
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci1. [Create a UIAbility](uiability-usage.md) in the stage model.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci2. Migrate the PageAbility code to the UIAbility.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci   The PageAbility lifecycle is basically the same as the UIAbility lifecycle. The table below describes the details.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci   | PageAbility| UIAbility| Mapping Description|
14e41f4b71Sopenharmony_ci   | -------- | -------- | -------- |
15e41f4b71Sopenharmony_ci   | onCreate(): void| onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void | The two methods have the same meaning and invoking time. In the stage model, parameters are added to the callback so that you can obtain startup-related data during creation.|
16e41f4b71Sopenharmony_ci   | NA | onWindowStageCreate(windowStage: window.WindowStage): void| This method is available only in the stage model. The callback is invoked when a window is created.|
17e41f4b71Sopenharmony_ci   | onActive(): void | on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void;<br>WindowStageEventType.ACTIVE | The two methods have the same meaning and invoking time. In the stage model, this method is moved to the window object.|
18e41f4b71Sopenharmony_ci   | onShow(): void | onForeground(): void | The two methods have the same meaning, invoking time, and parameters.|
19e41f4b71Sopenharmony_ci   | onNewWant(want: Want): void| onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void | The two methods have the same meaning and invoking time. In the stage model, the **LaunchParam** parameter is added to notify the application of the startup cause.|
20e41f4b71Sopenharmony_ci   | onInactive(): void| on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void;<br>WindowStageEventType.INACTIVE | The two methods have the same meaning and invoking time. In the stage model, this method is moved to the window object.|
21e41f4b71Sopenharmony_ci   | onHide(): void | onBackground(): void | The two methods have the same meaning, invoking time, and parameters.|
22e41f4b71Sopenharmony_ci   | NA | onWindowStageDestroy(): void | This method is available only in the stage model. The callback is invoked when a window is destroyed.|
23e41f4b71Sopenharmony_ci   | onDestroy(): void | onDestroy(): void | The two methods have the same meaning, invoking time, and parameters.|
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci   ![pageability-switch](figures/pageability-switch.png)
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci3. Adjust the migrated code, since the methods of loading pages are different.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci   - In the FA model, page loading is configured by setting page information in **config.json**.
30e41f4b71Sopenharmony_ci   - In the stage model, page loading is triggered through **windowStage.loadContent** in the **onWindowStageCreate** callback.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci   The following uses the task of displaying the **pages/Index** page after the ability is started as an example. In the FA model, add the following code in the **config.json** file:
33e41f4b71Sopenharmony_ci   
34e41f4b71Sopenharmony_ci   
35e41f4b71Sopenharmony_ci      ```json
36e41f4b71Sopenharmony_ci      "pages" : [
37e41f4b71Sopenharmony_ci          "pages/Index"
38e41f4b71Sopenharmony_ci      ]
39e41f4b71Sopenharmony_ci      ```
40e41f4b71Sopenharmony_ci   
41e41f4b71Sopenharmony_ci   In the stage model, implement the following API in **MainAbility**:
42e41f4b71Sopenharmony_ci   
43e41f4b71Sopenharmony_ci   
44e41f4b71Sopenharmony_ci     ```ts
45e41f4b71Sopenharmony_ci     import { UIAbility } from '@kit.AbilityKit';
46e41f4b71Sopenharmony_ci     import { hilog } from '@kit.PerformanceAnalysisKit';
47e41f4b71Sopenharmony_ci     import { window } from '@kit.ArkUI';
48e41f4b71Sopenharmony_ci   
49e41f4b71Sopenharmony_ci     export default class TestAbility extends UIAbility {
50e41f4b71Sopenharmony_ci       // ...
51e41f4b71Sopenharmony_ci       onWindowStageCreate(windowStage: window.WindowStage) {
52e41f4b71Sopenharmony_ci         hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
53e41f4b71Sopenharmony_ci         windowStage.loadContent('testability/pages/Index', (err, data) => {
54e41f4b71Sopenharmony_ci           if (err.code) {
55e41f4b71Sopenharmony_ci             hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
56e41f4b71Sopenharmony_ci             return;
57e41f4b71Sopenharmony_ci           }
58e41f4b71Sopenharmony_ci           hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
59e41f4b71Sopenharmony_ci             JSON.stringify(data) ?? '');
60e41f4b71Sopenharmony_ci         });
61e41f4b71Sopenharmony_ci       }
62e41f4b71Sopenharmony_ci       // ...
63e41f4b71Sopenharmony_ci     }
64e41f4b71Sopenharmony_ci     ```
65e41f4b71Sopenharmony_ci   
66e41f4b71Sopenharmony_ci   Then configure the page to load in the **resources/base/profile/main_pages.json** file.
67e41f4b71Sopenharmony_ci   
68e41f4b71Sopenharmony_ci     ```json
69e41f4b71Sopenharmony_ci     {
70e41f4b71Sopenharmony_ci       "src": [
71e41f4b71Sopenharmony_ci         "pages/Index"
72e41f4b71Sopenharmony_ci       ]
73e41f4b71Sopenharmony_ci     }
74e41f4b71Sopenharmony_ci     ```