未验证 提交 35b82349 编写于 作者: O openharmony_ci 提交者: Gitee

!13668 【元能力】示例代码整改

Merge pull request !13668 from donglin/master
......@@ -53,7 +53,7 @@ let want = {
abilityName: "EntryAbility"
};
abilityDelegator.startAbility(want, (err) => {
if (err.code !== 0) {
if (!err || err.code === 0) {
console.log("Success start ability.");
} else {
console.log("Failed start ability, error: " + JSON.stringify(err));
......
......@@ -292,8 +292,8 @@ export default class MySecondAbility extends UIAbility {
let applicationContext = this.context.getApplicationContext();
// 3.通过applicationContext注销监听应用内生命周期
applicationContext.off("abilityLifecycle", globalThis.lifecycleId, (error) => {
if (error.code != 0) {
console.log("unregisterAbilityLifecycleCallback failed, error: " + JSON.stringify(error));
if (error && error.code !== 0) {
console.log("unregisterAbilityLifecycleCallback fail, error: " + JSON.stringify(error));
} else {
console.log("unregisterAbilityLifecycleCallback success.");
}
......
......@@ -24,6 +24,7 @@ Ability的状态,该类型为枚举,可配合[AbilityRunningInfo](js-apis-in
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| INITIAL | 0 | 表示ability为初始化状态。|
| ACTIVE | 2 | 表示ability为获焦状态。 |
| FOREGROUND | 9 | 表示ability为前台状态。 |
| BACKGROUND | 10 | 表示ability为后台状态。 |
| FOREGROUNDING | 11 | 表示ability为前台调度中状态。 |
......@@ -70,7 +71,7 @@ const config = {
try {
abilityManager.updateConfiguration(config, (err) => {
if (err.code !== 0) {
if (err && err.code !== 0) {
console.log("updateConfiguration fail, err: " + JSON.stringify(err));
} else {
console.log("updateConfiguration success.");
......@@ -169,7 +170,7 @@ import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.getAbilityRunningInfos((err, data) => {
if (err.code !== 0) {
if (err && err.code !== 0) {
console.log("getAbilityRunningInfos fail, error: " + JSON.stringify(err));
} else {
console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data));
......@@ -256,7 +257,7 @@ let upperLimit = 10;
try {
abilityManager.getExtensionRunningInfos(upperLimit, (err, data) => {
if (err.code !== 0) {
if (err && err.code !== 0) {
console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err));
} else {
console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data));
......@@ -345,7 +346,7 @@ getTopAbility(callback: AsyncCallback\<ElementName>): void;
import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.getTopAbility((err, data) => {
if (err.code !== 0) {
if (err && err.code !== 0) {
console.log("getTopAbility fail, err: " + JSON.stringify(err));
} else {
console.log("getTopAbility success, data: " + JSON.stringify(data));
......
......@@ -40,8 +40,8 @@ static isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void
import appManager from '@ohos.app.ability.appManager';
appManager.isRunningInStabilityTest((err, flag) => {
if (err.code !== 0) {
console.log("isRunningInStabilityTest faile, err: " + JSON.stringify(err));
if (err && err.code !== 0) {
console.log("isRunningInStabilityTest fail, err: " + JSON.stringify(err));
} else {
console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag));
}
......@@ -146,8 +146,8 @@ isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;
import appManager from '@ohos.app.ability.appManager';
appManager.isRamConstrainedDevice((err, data) => {
if (err.code !== 0) {
console.log("isRamConstrainedDevice faile, err: " + JSON.stringify(err));
if (err && err.code !== 0) {
console.log("isRamConstrainedDevice fail, err: " + JSON.stringify(err));
} else {
console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data));
}
......@@ -216,8 +216,8 @@ getAppMemorySize(callback: AsyncCallback\<number>): void;
import appManager from '@ohos.app.ability.appManager';
appManager.getAppMemorySize((err, data) => {
if (err.code !== 0) {
console.log("getAppMemorySize faile, err: " + JSON.stringify(err));
if (err && err.code !== 0) {
console.log("getAppMemorySize fail, err: " + JSON.stringify(err));
} else {
console.log("The size of app memory is:" + JSON.stringify(data));
}
......@@ -294,8 +294,8 @@ getProcessRunningInformation(callback: AsyncCallback\<Array\<ProcessRunningInfor
import appManager from '@ohos.app.ability.appManager';
appManager.getProcessRunningInformation((err, data) => {
if (err.code !== 0) {
console.log("getProcessRunningInformation faile, err: " + JSON.stringify(err));
if (err && err.code !== 0) {
console.log("getProcessRunningInformation fail, err: " + JSON.stringify(err));
} else {
console.log("The process running information is:" + JSON.stringify(data));
}
......@@ -493,8 +493,8 @@ try {
// 2.注销应用状态监听器
function unregisterApplicationStateObserverCallback(err) {
if (err.code !== 0) {
console.log("unregisterApplicationStateObserverCallback faile, err: " + JSON.stringify(err));
if (err && err.code !== 0) {
console.log("unregisterApplicationStateObserverCallback fail, err: " + JSON.stringify(err));
} else {
console.log("unregisterApplicationStateObserverCallback success.");
}
......@@ -577,7 +577,7 @@ try {
appManager.off("applicationState", observerId).then((data) => {
console.log("unregisterApplicationStateObserver success, data: " + JSON.stringify(data));
}).catch((err) => {
console.log("unregisterApplicationStateObserver faile, err: " + JSON.stringify(err));
console.log("unregisterApplicationStateObserver fail, err: " + JSON.stringify(err));
})
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
......@@ -616,7 +616,7 @@ getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
import appManager from '@ohos.app.ability.appManager';
function getForegroundApplicationsCallback(err, data) {
if (err.code !== 0) {
if (err && err.code !== 0) {
console.log("getForegroundApplicationsCallback fail, err: " + JSON.stringify(err));
} else {
console.log("getForegroundApplicationsCallback success, data: " + JSON.stringify(data));
......@@ -749,7 +749,7 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
let accountId = 0;
function killProcessWithAccountCallback(err, data) {
if (err.code !== 0) {
if (err && err.code !== 0) {
console.log("killProcessWithAccountCallback fail, err: " + JSON.stringify(err));
} else {
console.log("killProcessWithAccountCallback success.");
......@@ -792,7 +792,7 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
function killProcessesByBundleNameCallback(err, data) {
if (err.code !== 0) {
if (err && err.code !== 0) {
console.log("killProcessesByBundleNameCallback fail, err: " + JSON.stringify(err));
} else {
console.log("killProcessesByBundleNameCallback success.");
......@@ -888,7 +888,7 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
function clearUpApplicationDataCallback(err, data) {
if (err) {
if (err && err.code !== 0) {
console.log("clearUpApplicationDataCallback fail, err: " + JSON.stringify(err));
} else {
console.log("clearUpApplicationDataCallback success.");
......
......@@ -19,11 +19,11 @@ onUnhandledException(errMsg: string): void;
**示例:**
```ts
import errorManager from '@ohos.app.ability.errorManager'
import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.log('HXW onUnhandledException, errorMsg: ', errorMsg);
console.log('onUnhandledException, errorMsg: ', errorMsg);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册