提交 665bcc00 编写于 作者: L lixia

windowExtensionContext.md指南ts示例代码arkts 告警修复

Signed-off-by: Nlixia <lixia110@huawei.com>
上级 b7b6fe61
...@@ -17,14 +17,16 @@ WindowExtensionContext模块提供[WindowExtensionAbility](js-apis-application-w ...@@ -17,14 +17,16 @@ WindowExtensionContext模块提供[WindowExtensionAbility](js-apis-application-w
在使用WindowExtensionContext的功能前,需要通过WindowExtensionAbility子类实例获取。 在使用WindowExtensionContext的功能前,需要通过WindowExtensionAbility子类实例获取。
```ts ```ts
import WindowExtensionAbility from '@ohos.application.WindowExtensionAbility'; import WindowExtensionAbility from '@ohos.application.WindowExtensionAbility';
import WindowExtensionContext from 'application/WindowExtensionContext';
let context; let context: WindowExtensionContext | null = null;
class WindowExtAbility extends WindowExtensionAbility {
onConnect() { class WindowExtAbility extends WindowExtensionAbility {
context = this.context; // 获取WindowExtensionContext onConnect() {
} context = this.context; // 获取WindowExtensionContext
} }
}
``` ```
## WindowExtensionContext.startAbility ## WindowExtensionContext.startAbility
...@@ -46,28 +48,36 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void& ...@@ -46,28 +48,36 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&
**示例:** **示例:**
```ts ```ts
var want = { import { BusinessError } from '@ohos.base';
bundleName: 'com.example.myapplication', import Want from '@ohos.app.ability.Want';
abilityName: 'MainAbility' import StartOptions from '@ohos.app.ability.StartOptions';
};
var options = { let want: Want = {
windowMode: 102 bundleName: 'com.example.myapplication',
}; abilityName: 'MainAbility'
};
try { let options: StartOptions = {
this.context.startAbility(want, options, (error) => { windowMode: 102
if (error.code) { };
// 处理业务逻辑错误
console.error('startAbility failed, error.code: ${error.code}, error.message: ${error.message}'); try {
return; this.context.startAbility(want, options, (error: BusinessError) => {
} let message = (error as BusinessError).message;
// 执行正常业务 let errCode = (error as BusinessError).code;
console.log('startAbility succeed'); if (errCode) {
}); // 处理业务逻辑错误
} catch (paramError) { console.error('startAbility failed, error.code: ${errCode}, error.message: ${message}');
// 处理入参错误异常 return;
console.error('error.code: ${paramError.code}, error.message: ${paramError.message}'); }
} // 执行正常业务
console.log('startAbility succeed');
});
} catch (paramError) {
// 处理入参错误异常
let message = (paramError as BusinessError).message;
let errCode = (paramError as BusinessError).code;
console.error('error.code: ${errCode}, error.message: ${message}');
}
``` ```
## WindowExtensionContext.startAbility ## WindowExtensionContext.startAbility
...@@ -94,26 +104,34 @@ startAbility(want: Want, options?: StartOptions): Promise\<void> ...@@ -94,26 +104,34 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>
**示例:** **示例:**
```ts ```ts
var want = { import { BusinessError } from '@ohos.base';
bundleName: 'com.example.myapp', import Want from '@ohos.app.ability.Want';
abilityName: 'MainAbility' import StartOptions from '@ohos.app.ability.StartOptions';
};
var options = { let want: Want = {
windowMode: 102, bundleName: 'com.example.myapp',
}; abilityName: 'MainAbility'
};
try { let options: StartOptions = {
this.context.startAbility(want, options) windowMode: 102,
.then((data) => { };
// 执行正常业务
console.log('startAbility succeed'); try {
}) this.context.startAbility(want, options)
.catch((error) => { .then(() => {
// 处理业务逻辑错误 // 执行正常业务
console.error('startAbility failed, error.code: ${error.code}, error.message: ${error.message}'); console.log('startAbility succeed');
}); })
} catch (paramError) { .catch((error: BusinessError) => {
// 处理入参错误异常 // 处理业务逻辑错误
console.error('error.code: ${paramError.code}, error.message: ${paramError.message}'); let message = (error as BusinessError).message;
} let errCode = (error as BusinessError).code;
console.error('startAbility failed, error.code: ${errCode}, error.message: ${message}');
});
} catch (paramError) {
// 处理入参错误异常
let message = (paramError as BusinessError).message;
let errCode = (paramError as BusinessError).code;
console.error('error.code: ${errCode}, error.message: ${message}');
}
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册