Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
06f08ef1
D
Docs
项目概览
OpenHarmony
/
Docs
12 个月 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
06f08ef1
编写于
1月 16, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 16, 2023
浏览文件
操作
浏览文件
下载
差异文件
!13634 UIAbilityContext示例代码优化
Merge pull request !13634 from 张亚菲/zyf
上级
9cfb8dca
0538ce3b
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
71 addition
and
71 deletion
+71
-71
zh-cn/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md
...erence/apis/js-apis-inner-application-uiAbilityContext.md
+71
-71
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md
浏览文件 @
06f08ef1
...
...
@@ -61,7 +61,7 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
**示例:**
```
ts
var
want
=
{
let
want
=
{
bundleName
:
"
com.example.myapp
"
,
abilityName
:
"
MyAbility
"
};
...
...
@@ -126,12 +126,12 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
};
var
options
=
{
let
options
=
{
windowMode
:
0
};
...
...
@@ -200,11 +200,11 @@ startAbility(want: Want, options?: StartOptions): Promise<void>;
**示例:**
```
ts
var
want
=
{
let
want
=
{
bundleName
:
"
com.example.myapp
"
,
abilityName
:
"
MyAbility
"
};
var
options
=
{
let
options
=
{
windowMode
:
0
,
};
...
...
@@ -267,7 +267,7 @@ startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>):
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
...
...
@@ -333,12 +333,12 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
};
var
options
=
{
let
options
=
{
windowMode
:
0
,
};
...
...
@@ -409,11 +409,11 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityRes
**示例:**
```
ts
var
want
=
{
let
want
=
{
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
};
var
options
=
{
let
options
=
{
windowMode
:
0
,
};
...
...
@@ -481,12 +481,12 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
};
var
accountId
=
100
;
let
accountId
=
100
;
try
{
this
.
context
.
startAbilityForResultWithAccount
(
want
,
accountId
,
(
error
,
result
)
=>
{
...
...
@@ -555,13 +555,13 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
};
var
accountId
=
100
;
var
options
=
{
let
accountId
=
100
;
let
options
=
{
windowMode
:
0
};
...
...
@@ -636,13 +636,13 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
};
var
accountId
=
100
;
var
options
=
{
let
accountId
=
100
;
let
options
=
{
windowMode
:
0
};
...
...
@@ -697,7 +697,7 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
...
...
@@ -753,7 +753,7 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
...
...
@@ -813,12 +813,12 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
};
var
accountId
=
100
;
let
accountId
=
100
;
try
{
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
error
)
=>
{
...
...
@@ -873,16 +873,16 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
};
var
accountId
=
100
;
let
accountId
=
100
;
try
{
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
((
data
)
=>
{
.
then
(()
=>
{
// 执行正常业务
console
.
log
(
'
startServiceExtensionAbilityWithAccount succeed
'
);
})
...
...
@@ -929,7 +929,7 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
...
...
@@ -984,7 +984,7 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
...
...
@@ -992,7 +992,7 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
try
{
this
.
context
.
stopServiceExtensionAbility
(
want
)
.
then
((
data
)
=>
{
.
then
(()
=>
{
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbility succeed
'
);
})
...
...
@@ -1043,12 +1043,12 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
};
var
accountId
=
100
;
let
accountId
=
100
;
try
{
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
error
)
=>
{
...
...
@@ -1102,16 +1102,16 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
};
var
accountId
=
100
;
let
accountId
=
100
;
try
{
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
((
data
)
=>
{
.
then
(()
=>
{
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbilityWithAccount succeed
'
);
})
...
...
@@ -1250,13 +1250,13 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<voi
**示例:**
```
ts
var
want
=
{
let
want
=
{
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
}
var
resultCode
=
100
;
let
resultCode
=
100
;
// 返回给接口调用方AbilityResult信息
var
abilityResult
=
{
let
abilityResult
=
{
want
,
resultCode
}
...
...
@@ -1314,20 +1314,20 @@ terminateSelfWithResult(parameter: AbilityResult): Promise<void>;
**示例:**
```
ts
var
want
=
{
let
want
=
{
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
}
var
resultCode
=
100
;
let
resultCode
=
100
;
// 返回给接口调用方AbilityResult信息
var
abilityResult
=
{
let
abilityResult
=
{
want
,
resultCode
}
try
{
this
.
context
.
terminateSelfWithResult
(
abilityResult
)
.
then
((
data
)
=>
{
.
then
(()
=>
{
// 执行正常业务
console
.
log
(
'
terminateSelfWithResult succeed
'
);
})
...
...
@@ -1378,12 +1378,12 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
};
var
options
=
{
let
options
=
{
onConnect
(
elementName
,
remote
)
{
console
.
log
(
'
----------- onConnect -----------
'
)
},
...
...
@@ -1395,7 +1395,7 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
}
}
var
connection
=
null
;
let
connection
=
null
;
try
{
connection
=
this
.
context
.
connectServiceExtensionAbility
(
want
,
options
);
}
catch
(
paramError
)
{
...
...
@@ -1444,13 +1444,13 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
ServiceExtensionAbility
"
};
var
accountId
=
100
;
var
options
=
{
let
accountId
=
100
;
let
options
=
{
onConnect
(
elementName
,
remote
)
{
console
.
log
(
'
----------- onConnect -----------
'
)
},
...
...
@@ -1462,7 +1462,7 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
}
}
var
connection
=
null
;
let
connection
=
null
;
try
{
connection
=
this
.
context
.
connectServiceExtensionAbilityWithAccount
(
want
,
accountId
,
options
);
}
catch
(
paramError
)
{
...
...
@@ -1505,11 +1505,11 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>;
```
ts
// connection为connectServiceExtensionAbility中的返回值
var
connection
=
1
;
let
connection
=
1
;
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
)
.
then
((
data
)
=>
{
.
then
(()
=>
{
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
})
...
...
@@ -1553,7 +1553,7 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<vo
```
ts
// connection为connectServiceExtensionAbility中的返回值
var
connection
=
1
;
let
connection
=
1
;
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
,
(
error
)
=>
{
...
...
@@ -1623,10 +1623,10 @@ startAbilityByCall(want: Want): Promise<Caller>;
后台启动:
```
ts
var
caller
=
undefined
;
let
caller
=
undefined
;
// 后台启动Ability,不配置parameters
var
wantBackground
=
{
let
wantBackground
=
{
bundleName
:
"
com.example.myservice
"
,
moduleName
:
"
entry
"
,
abilityName
:
"
EntryAbility
"
,
...
...
@@ -1654,10 +1654,10 @@ startAbilityByCall(want: Want): Promise<Caller>;
前台启动:
```
ts
var
caller
=
undefined
;
let
caller
=
undefined
;
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
var
wantForeground
=
{
let
wantForeground
=
{
bundleName
:
"
com.example.myservice
"
,
moduleName
:
"
entry
"
,
abilityName
:
"
EntryAbility
"
,
...
...
@@ -1731,12 +1731,12 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
};
var
accountId
=
100
;
let
accountId
=
100
;
try
{
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
(
error
)
=>
{
...
...
@@ -1804,13 +1804,13 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
};
var
accountId
=
100
;
var
options
=
{
let
accountId
=
100
;
let
options
=
{
windowMode
:
0
};
...
...
@@ -1879,19 +1879,19 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
**示例:**
```
ts
var
want
=
{
let
want
=
{
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
abilityName
:
"
EntryAbility
"
};
var
accountId
=
100
;
var
options
=
{
let
accountId
=
100
;
let
options
=
{
windowMode
:
0
};
try
{
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
)
.
then
((
data
)
=>
{
.
then
(()
=>
{
// 执行正常业务
console
.
log
(
'
startAbilityWithAccount succeed
'
);
})
...
...
@@ -1994,9 +1994,9 @@ setMissionIcon(icon: image.PixelMap, callback:AsyncCallback\<void>): void;
```
ts
import
image
from
'
@ohos.multimedia.image
'
;
var
imagePixelMap
;
var
color
=
new
ArrayBuffer
(
0
);
var
initializationOptions
=
{
let
imagePixelMap
;
let
color
=
new
ArrayBuffer
(
0
);
let
initializationOptions
=
{
size
:
{
height
:
100
,
width
:
100
...
...
@@ -2047,9 +2047,9 @@ setMissionIcon(icon: image.PixelMap): Promise\<void>;
**示例:**
```
ts
var
imagePixelMap
;
var
color
=
new
ArrayBuffer
(
0
);
var
initializationOptions
=
{
let
imagePixelMap
;
let
color
=
new
ArrayBuffer
(
0
);
let
initializationOptions
=
{
size
:
{
height
:
100
,
width
:
100
...
...
@@ -2094,7 +2094,7 @@ restoreWindowStage(localStorage: LocalStorage) : void;
**示例:**
```
ts
var
storage
=
new
LocalStorage
();
let
storage
=
new
LocalStorage
();
this
.
context
.
restoreWindowStage
(
storage
);
```
...
...
@@ -2122,6 +2122,6 @@ isTerminating(): boolean;
**示例:**
```
ts
var
isTerminating
=
this
.
context
.
isTerminating
();
let
isTerminating
=
this
.
context
.
isTerminating
();
console
.
log
(
'
ability state :
'
+
isTerminating
);
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录