提交 2b161224 编写于 作者: G Gloria

Update docs against 21425+21455

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 bae87b24
...@@ -35,8 +35,8 @@ Assume that your application has two UIAbility components: EntryAbility and Func ...@@ -35,8 +35,8 @@ Assume that your application has two UIAbility components: EntryAbility and Func
let want = { let want = {
deviceId: '', // An empty deviceId indicates the local device. deviceId: '', // An empty deviceId indicates the local device.
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
moduleName: 'func', // moduleName is optional. moduleName: 'func', // moduleName is optional.
abilityName: 'FuncAbility',
parameters: { // Custom information. parameters: { // Custom information.
info: 'From the Index page of EntryAbility', info: 'From the Index page of EntryAbility',
}, },
...@@ -100,8 +100,8 @@ When starting FuncAbility from EntryAbility, you may want the result to be retur ...@@ -100,8 +100,8 @@ When starting FuncAbility from EntryAbility, you may want the result to be retur
let want = { let want = {
deviceId: '', // An empty deviceId indicates the local device. deviceId: '', // An empty deviceId indicates the local device.
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
moduleName: 'func', // moduleName is optional. moduleName: 'func', // moduleName is optional.
abilityName: 'FuncAbility',
parameters: { // Custom information. parameters: { // Custom information.
info: 'From the Index page of EntryAbility', info: 'From the Index page of EntryAbility',
}, },
...@@ -123,8 +123,8 @@ When starting FuncAbility from EntryAbility, you may want the result to be retur ...@@ -123,8 +123,8 @@ When starting FuncAbility from EntryAbility, you may want the result to be retur
resultCode: RESULT_CODE, resultCode: RESULT_CODE,
want: { want: {
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
moduleName: 'func', // moduleName is optional.
abilityName: 'FuncAbility', abilityName: 'FuncAbility',
moduleName: 'func',
parameters: { parameters: {
info: 'From the Index page of FuncAbility', info: 'From the Index page of FuncAbility',
}, },
...@@ -220,6 +220,7 @@ The following example describes how to start the UIAbility of another applicatio ...@@ -220,6 +220,7 @@ The following example describes how to start the UIAbility of another applicatio
``` ```
The following figure shows the effect. When you click **Open PDF**, a dialog box is displayed for you to select the application to use. The following figure shows the effect. When you click **Open PDF**, a dialog box is displayed for you to select the application to use.
![](figures/uiability-intra-device-interaction.png) ![](figures/uiability-intra-device-interaction.png)
3. To stop the **UIAbility** instance when the document application is not in use, call [terminateSelf()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateself). 3. To stop the **UIAbility** instance when the document application is not in use, call [terminateSelf()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateself).
...@@ -296,9 +297,9 @@ If you want to obtain the return result when using implicit Want to start the UI ...@@ -296,9 +297,9 @@ If you want to obtain the return result when using implicit Want to start the UI
let abilityResult = { let abilityResult = {
resultCode: RESULT_CODE, resultCode: RESULT_CODE,
want: { want: {
bundleName: 'com.example.myapplication', bundleName: 'com.example.funcapplication',
moduleName: 'entry', // moduleName is optional.
abilityName: 'EntryAbility', abilityName: 'EntryAbility',
moduleName: 'entry',
parameters: { parameters: {
payResult: 'OKay', payResult: 'OKay',
}, },
...@@ -366,8 +367,8 @@ let context = ...; // UIAbilityContext ...@@ -366,8 +367,8 @@ let context = ...; // UIAbilityContext
let want = { let want = {
deviceId: '', // An empty deviceId indicates the local device. deviceId: '', // An empty deviceId indicates the local device.
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
moduleName: 'func', // moduleName is optional. moduleName: 'func', // moduleName is optional.
abilityName: 'FuncAbility',
parameters: { // Custom information. parameters: { // Custom information.
info: 'From the Index page of EntryAbility', info: 'From the Index page of EntryAbility',
}, },
...@@ -401,9 +402,9 @@ When the initiator UIAbility starts another UIAbility, it usually needs to redir ...@@ -401,9 +402,9 @@ When the initiator UIAbility starts another UIAbility, it usually needs to redir
let context = ...; // UIAbilityContext let context = ...; // UIAbilityContext
let want = { let want = {
deviceId: '', // An empty deviceId indicates the local device. deviceId: '', // An empty deviceId indicates the local device.
bundleName: 'com.example.myapplication', bundleName: 'com.example.funcapplication',
abilityName: 'FuncAbility', moduleName: 'entry', // moduleName is optional.
moduleName: 'func', // moduleName is optional. abilityName: 'EntryAbility',
parameters: { // Custom parameter used to pass the page information. parameters: { // Custom parameter used to pass the page information.
router: 'funcA', router: 'funcA',
}, },
...@@ -423,25 +424,25 @@ When the target UIAbility is started for the first time, in the **onWindowStageC ...@@ -423,25 +424,25 @@ When the target UIAbility is started for the first time, in the **onWindowStageC
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility' import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Window from '@ohos.window' import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import window from '@ohos.window';
export default class FuncAbility extends UIAbility { export default class FuncAbility extends UIAbility {
funcAbilityWant; funcAbilityWant: Want;
onCreate(want, launchParam) { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
// Receive the parameters passed by the initiator UIAbility. // Receive the parameters passed by the initiator UIAbility.
this.funcAbilityWant = want; this.funcAbilityWant = want;
} }
onWindowStageCreate(windowStage: Window.WindowStage) { onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created. Set a main page for this UIAbility. // Main window is created. Set a main page for this UIAbility.
let url = 'pages/Index'; let url = 'pages/Index';
if (this.funcAbilityWant?.parameters?.router) { if (this.funcAbilityWant?.parameters?.router && this.funcAbilityWant.parameters.router === 'funcA') {
if (this.funcAbilityWant.parameters.router === 'funA') {
url = 'pages/Second'; url = 'pages/Second';
} }
}
windowStage.loadContent(url, (err, data) => { windowStage.loadContent(url, (err, data) => {
... ...
}); });
...@@ -449,52 +450,91 @@ export default class FuncAbility extends UIAbility { ...@@ -449,52 +450,91 @@ export default class FuncAbility extends UIAbility {
} }
``` ```
### Starting a Page When the Target UIAbility Is Not Started for the First Time ### Starting a Page When the Target UIAbility Is Not Started for the First Time
You start application A, and its home page is displayed. Then you return to the home screen and start application B. Now you need to start application A again from application B and access a specified page of application A. An example scenario is as follows: When you open the home page of the SMS application and return to the home screen, the SMS application is in the opened state with its home page. Then you open the home page of the Contacts application, access user A's details page, and touch the SMS icon to send an SMS message to user A. The SMS application is started again and the sending page is displayed. If the target UIAbility has been started, the initialization logic is not executed again. Instead, the **onNewWant()** lifecycle callback is directly triggered. To implement redirection, parse the required parameters in **onNewWant()**.
![uiability_not_first_started](figures/uiability_not_first_started.png) An example scenario is as follows:
1. A user opens the SMS application. The UIAbility instance of the SMS application is started, and the home page of the application is displayed.
2. The user returns to the home screen, and the SMS application switches to the background.
3. The user opens the Contacts application and finds a contact.
4. The user touches the SMS button next to the contact. The UIAbility instance of the SMS application is restarted.
5. Since the UIAbility instance of the SMS application has been started, the **onNewWant()** callback of the UIAbility is triggered, and the initialization logic such as **onCreate()** and **onWindowStageCreate()** is skipped.
```mermaid
sequenceDiagram
Participant U as User
Participant S as SMS app
Participant C as Contacts app
U->>S: Open the SMS app.
S-->>U: The home page of the SMS app is displayed.
U->>S: Return to the home screen.
S->>S: The SMS app enters the background.
U->>C: Open the Contacts app.
C-->>U: The page of the Contact app is displayed.
U->>C: Touch the SMS button next to a contact.
C->>S: Start the SMS app with Want.
S-->>U: The page for sending an SMS message to the contact is displayed.
```
In summary, when a UIAbility instance of application A has been created and the main page of the UIAbility instance is displayed, you need to start the UIAbility of application A from application B and access a different page. The development procedure is as follows:
1. In the target UIAbility, the **Index** page is loaded by default. The UIAbility instance has been created, and the **onNewWant()** callback rather than **onCreate()** and **onWindowStageCreate()** will be invoked. In the **onNewWant()** callback, parse the **want** parameter and bind it to the global variable **globalThis**. 1. When the UIAbility instance of the SMS application is started for the first time, call [getUIContext()](../reference/apis/js-apis-window.md#getuicontext10) in the **onWindowStageCreate()** lifecycle callback to obtain the [UIContext](../reference/apis/js-apis-arkui-UIContext.md).
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility' import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import window from '@ohos.window';
import { Router, UIContext } from '@ohos.arkui.UIContext';
export default class EntryAbility extends UIAbility {
funcAbilityWant: Want;
uiContext: UIContext;
export default class FuncAbility extends UIAbility {
onNewWant(want, launchParam) {
// Receive the parameters passed by the initiator UIAbility.
globalThis.funcAbilityWant = want;
... ...
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created. Set a main page for this UIAbility.
...
let windowClass: window.Window;
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error(`Failed to obtain the main window. Code is ${err.code}, message is ${err.message}`);
return;
}
windowClass = data;
this.uiContext = windowClass.getUIContext();
})
} }
} }
``` ```
2. In FuncAbility, use the router module to implement redirection to the specified page on the **Index** page. Because the **Index** page of FuncAbility is active, the variable will not be declared again and the **aboutToAppear()** callback will not be triggered. Therefore, the page routing functionality can be implemented in the **onPageShow()** callback of the **Index** page. 2. Parse the **want** parameter passed in the **onNewWant()** callback of the UIAbility of the SMS application, call [getRouter()](../reference/apis/js-apis-arkui-UIContext.md#getrouter) in the **UIContext** class to obtain a [Router](../reference/apis/js-apis-arkui-UIContext.md#router) instance, and specify the target page. When the UIAbility instance of the SMS application is started again, the specified page of the UIAbility instance of the SMS application is displayed.
```ts ```ts
import router from '@ohos.router'; export default class EntryAbility extends UIAbility {
funcAbilityWant: Want;
@Entry uiContext: UIContext;
@Component
struct Index { onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam) {
onPageShow() { if (want?.parameters?.router && want.parameters.router === 'funcA') {
let funcAbilityWant = globalThis.funcAbilityWant; let funcAUrl = 'pages/Second';
let url2 = funcAbilityWant?.parameters?.router; let router: Router = this.uiContext.getRouter();
if (url2 && url2 === 'funcA') { router.pushUrl({
router.replaceUrl({ url: funcAUrl
url: 'pages/Second', }).catch((err) => {
console.error(`Failed to push url. Code is ${err.code}, message is ${err.message}`);
}) })
} }
} }
// Page display.
build() {
... ...
} }
}
``` ```
> **NOTE** > **NOTE**
......
...@@ -85,7 +85,7 @@ The **FormBindingData** class has the following APIs. For details, see [FormBind ...@@ -85,7 +85,7 @@ The **FormBindingData** class has the following APIs. For details, see [FormBind
| API| Description| | API| Description|
| -------- | -------- | | -------- | -------- |
| createFormBindingData(obj?: Object \ string): FormBindingData| | Creates a **FormBindingData** object.| | createFormBindingData(obj?:&nbsp;Object&nbsp;\|&nbsp;string):&nbsp;FormBindingData | Creates a **FormBindingData** object. |
## How to Develop ## How to Develop
...@@ -327,9 +327,11 @@ For details about how to implement persistent data storage, see [Application Dat ...@@ -327,9 +327,11 @@ For details about how to implement persistent data storage, see [Application Dat
The **Want** object passed in by the widget host to the widget provider contains a flag that specifies whether the requested widget is normal or temporary. The **Want** object passed in by the widget host to the widget provider contains a flag that specifies whether the requested widget is normal or temporary.
- Normal widget: a widget persistently used by the widget host - Normal widget: a widget persistently used by the widget host, for example, a widget added to the home screen.
- Temporary widget: a widget temporarily used by the widget host - Temporary widget: a widget temporarily used by the widget host, for example, the widget displayed when you swipe up on a widget application.
Converting a temporary widget to a normal one: After you swipe up on a widget application, a temporary widget is displayed. If you touch the pin button on the widget, it is displayed as a normal widget on the home screen.
Data of a temporary widget will be deleted on the Widget Manager if the widget framework is killed and restarted. The widget provider, however, is not notified of the deletion and still keeps the data. Therefore, the widget provider needs to clear the data of temporary widgets proactively if the data has been kept for a long period of time. If the widget host has converted a temporary widget into a normal one, the widget provider should change the widget data from temporary storage to persistent storage. Otherwise, the widget data may be deleted by mistake. Data of a temporary widget will be deleted on the Widget Manager if the widget framework is killed and restarted. The widget provider, however, is not notified of the deletion and still keeps the data. Therefore, the widget provider needs to clear the data of temporary widgets proactively if the data has been kept for a long period of time. If the widget host has converted a temporary widget into a normal one, the widget provider should change the widget data from temporary storage to persistent storage. Otherwise, the widget data may be deleted by mistake.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册