Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
d38e32f5
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
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看板
未验证
提交
d38e32f5
编写于
9月 06, 2023
作者:
O
openharmony_ci
提交者:
Gitee
9月 06, 2023
浏览文件
操作
浏览文件
下载
差异文件
!24128 元能力arkts整改补充
Merge pull request !24128 from liuliu/amsfix
上级
4fe6dc88
c37295bc
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
42 addition
and
73 deletion
+42
-73
zh-cn/application-dev/application-models/start-page.md
zh-cn/application-dev/application-models/start-page.md
+15
-7
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md
...ence/apis/js-apis-app-ability-abilityLifecycleCallback.md
+1
-1
zh-cn/application-dev/reference/apis/js-apis-app-ability-applicationStateChangeCallback.md
...pis/js-apis-app-ability-applicationStateChangeCallback.md
+14
-59
zh-cn/application-dev/reference/apis/js-apis-inner-application-extensionContext.md
...erence/apis/js-apis-inner-application-extensionContext.md
+12
-6
未找到文件。
zh-cn/application-dev/application-models/start-page.md
浏览文件 @
d38e32f5
...
...
@@ -30,7 +30,7 @@ async function restartAbility() {
在目标端PageAbility的onNewWant回调中获取包含页面信息的want参数:
```
ts
import
Want
from
'
@ohos.app.ability.Want
'
;
// GlobalContext.ts 构造单例对象
export
class
GlobalContext
{
private
constructor
()
{}
private
static
instance
:
GlobalContext
;
...
...
@@ -51,6 +51,11 @@ export class GlobalContext {
this
.
_objects
.
set
(
key
,
objectClass
);
}
}
```
```
ts
import
Want
from
'
@ohos.application.Want
'
;
import
{
GlobalContext
}
from
'
./GlobalContext
'
;
export
default
class
EntryAbility
{
onNewWant
(
want
:
Want
)
{
...
...
@@ -63,8 +68,9 @@ export default class EntryAbility{
在目标端页面的自定义组件中获取包含页面信息的want参数并根据uri做路由处理:
```
ts
import
Want
from
'
@ohos.application.Want
'
;
import
router
from
'
@ohos.router
'
;
import
{
GlobalContext
}
from
'
../GlobalContext
'
import
{
GlobalContext
}
from
'
../GlobalContext
'
;
@
Entry
@
Component
...
...
@@ -73,12 +79,14 @@ struct Index {
onPageShow
()
{
console
.
info
(
'
Index onPageShow
'
)
let
newWant
:
Want
=
GlobalContext
.
getContext
().
getObject
(
"
newWant
"
)
if
(
newWant
.
hasOwnProperty
(
"
page
"
))
{
router
.
push
({
url
:
newWant
.
page
});
let
newWant
=
GlobalContext
.
getContext
().
getObject
(
"
newWant
"
)
as
Want
if
(
newWant
.
parameters
)
{
if
(
newWant
.
parameters
.
page
)
{
router
.
push
({
url
:
newWant
.
parameters
.
page
});
GlobalContext
.
getContext
().
setObject
(
"
newWant
"
,
undefined
)
}
}
}
build
()
{
Row
()
{
...
...
@@ -160,7 +168,7 @@ export default class EntryAbility {
if
(
want
.
parameters
)
{
if
(
want
.
parameters
.
page
)
{
router
.
push
({
url
:
want
.
parameters
.
page
url
:
want
.
parameters
.
page
as
string
})
}
}
...
...
zh-cn/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md
浏览文件 @
d38e32f5
...
...
@@ -333,7 +333,7 @@ import { GlobalContext } from '../GlobalContext'
export
default
class
MySecondAbility
extends
UIAbility
{
onDestroy
()
{
let
applicationContext
=
this
.
context
.
getApplicationContext
();
let
lifecycleId
:
number
=
GlobalContext
.
getContext
().
getObject
(
"
lifecycleId
"
)
;
let
lifecycleId
=
GlobalContext
.
getContext
().
getObject
(
"
lifecycleId
"
)
as
number
;
// 3.通过applicationContext注销监听应用内生命周期
applicationContext
.
off
(
'
abilityLifecycle
'
,
lifecycleId
,
(
error
)
=>
{
if
(
error
&&
error
.
code
!==
0
)
{
...
...
zh-cn/application-dev/reference/apis/js-apis-app-ability-applicationStateChangeCallback.md
浏览文件 @
d38e32f5
...
...
@@ -27,53 +27,30 @@ onApplicationForeground(): void;
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
ApplicationStateChangeCallback
from
'
@ohos.app.ability.ApplicationStateChangeCallback
'
;
// 构造单例对象
export
class
GlobalContext
{
private
constructor
()
{}
private
static
instance
:
GlobalContext
;
private
_objects
=
new
Map
<
string
,
Object
>
();
public
static
getContext
():
GlobalContext
{
if
(
!
GlobalContext
.
instance
)
{
GlobalContext
.
instance
=
new
GlobalContext
();
}
return
GlobalContext
.
instance
;
}
getObject
(
value
:
string
):
Object
|
undefined
{
return
this
.
_objects
.
get
(
value
);
}
setObject
(
key
:
string
,
objectClass
:
Object
):
void
{
this
.
_objects
.
set
(
key
,
objectClass
);
}
}
let
applicationStateChangeCallback
:
ApplicationStateChangeCallback
=
{
onApplicationForeground
()
{
console
.
info
(
'
applicationStateChangeCallback onApplicationForeground
'
);
},
onApplicationBackground
()
{
console
.
info
(
'
applicationStateChangeCallback onApplicationBackground
'
);
}
}
GlobalContext
.
getContext
().
setObject
(
"
applicationStateChangeCallback
"
,
applicationStateChangeCallback
);
export
default
class
MyAbility
extends
UIAbility
{
onCreate
()
{
console
.
log
(
'
MyAbility onCreate
'
);
GlobalContext
.
getContext
().
setObject
(
"
applicationContext
"
,
this
.
context
.
getApplicationContext
());
// 1.获取applicationContext
let
applicationContext
=
GlobalContext
.
getContext
().
getObject
(
"
applicationContext
"
);
let
applicationContext
=
this
.
context
.
getApplicationContext
(
);
// 2.通过applicationContext注册应用前后台状态监听
if
(
applicationContext
!=
undefined
)
{
applicationContext
.
on
(
'
applicationStateChange
'
,
GlobalContext
.
getContext
().
getObject
(
"
applicationStateChangeCallback
"
));
applicationContext
.
on
(
'
applicationStateChange
'
,
applicationStateChangeCallback
);
}
}
onDestroy
()
{
let
applicationContext
=
GlobalContext
.
getContext
().
getObject
(
"
applicationContext
"
);
let
applicationContext
=
this
.
context
.
getApplicationContext
(
);
// 1.通过applicationContext解除注册应用前后台状态监听
if
(
applicationContext
!=
undefined
)
{
applicationContext
.
off
(
'
applicationStateChange
'
,
GlobalContext
.
getContext
().
getObject
(
"
applicationStateChangeCallback
"
));
applicationContext
.
off
(
'
applicationStateChange
'
,
applicationStateChangeCallback
);
}
}
}
...
...
@@ -93,53 +70,31 @@ onApplicationBackground(): void;
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
ApplicationStateChangeCallback
from
'
@ohos.app.ability.ApplicationStateChangeCallback
'
;
export
class
GlobalContext
{
private
constructor
()
{}
private
static
instance
:
GlobalContext
;
private
_objects
=
new
Map
<
string
,
Object
>
();
public
static
getContext
():
GlobalContext
{
if
(
!
GlobalContext
.
instance
)
{
GlobalContext
.
instance
=
new
GlobalContext
();
}
return
GlobalContext
.
instance
;
}
getObject
(
value
:
string
):
Object
|
undefined
{
return
this
.
_objects
.
get
(
value
);
}
setObject
(
key
:
string
,
objectClass
:
Object
):
void
{
this
.
_objects
.
set
(
key
,
objectClass
);
}
}
let
applicationStateChangeCallback
:
ApplicationStateChangeCallback
=
{
onApplicationForeground
()
{
console
.
info
(
'
applicationStateChangeCallback onApplicationForeground
'
);
},
onApplicationBackground
()
{
console
.
info
(
'
applicationStateChangeCallback onApplicationBackground
'
);
}
}
GlobalContext
.
getContext
().
setObject
(
"
applicationStateChangeCallback
"
,
applicationStateChangeCallback
);
export
default
class
MyAbility
extends
UIAbility
{
onCreate
()
{
console
.
log
(
'
MyAbility onCreate
'
);
GlobalContext
.
getContext
().
setObject
(
"
applicationContext
"
,
this
.
context
.
getApplicationContext
());
// 1.获取applicationContext
let
applicationContext
=
GlobalContext
.
getContext
().
getObject
(
"
applicationContext
"
);
let
applicationContext
=
this
.
context
.
getApplicationContext
(
);
// 2.通过applicationContext注册应用前后台状态监听
if
(
applicationContext
!=
undefined
)
{
applicationContext
.
on
(
'
applicationStateChange
'
,
GlobalContext
.
getContext
().
getObject
(
"
applicationStateChangeCallback
"
));
applicationContext
.
on
(
'
applicationStateChange
'
,
applicationStateChangeCallback
);
}
console
.
log
(
'
Resgiter applicationStateChangeCallback
'
);
}
onDestroy
()
{
let
applicationContext
=
GlobalContext
.
getContext
().
getObject
(
"
applicationContext
"
);
let
applicationContext
=
this
.
context
.
getApplicationContext
(
);
// 1.通过applicationContext解除注册应用前后台状态监听
if
(
applicationContext
!=
undefined
)
{
applicationContext
.
off
(
'
applicationStateChange
'
,
GlobalContext
.
getContext
().
getObject
(
"
applicationStateChangeCallback
"
));
applicationContext
.
off
(
'
applicationStateChange
'
,
applicationStateChangeCallback
);
}
}
}
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-application-extensionContext.md
浏览文件 @
d38e32f5
...
...
@@ -37,10 +37,7 @@ ExtensionContext主要用于查询所属Extension的信息、Module的配置信
三个Module内都定义一个相同名称的ServiceExtension:
```
ts
import
ServiceExtension
from
'
@ohos.app.ability.ServiceExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
rpc
from
'
@ohos.rpc
'
;
// 单例对象 GlobalContext.ts
export
class
GlobalContext
{
private
constructor
()
{}
private
static
instance
:
GlobalContext
;
...
...
@@ -61,6 +58,13 @@ export class GlobalContext {
this
.
_objects
.
set
(
key
,
objectClass
);
}
}
```
```
ts
import
ServiceExtension
from
'
@ohos.app.ability.ServiceExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
rpc
from
'
@ohos.rpc
'
;
import
{
GlobalContext
}
from
'
../GlobalContext
'
export
default
class
TheServiceExtension
extends
ServiceExtension
{
onCreate
(
want
:
Want
)
{
...
...
@@ -109,7 +113,8 @@ export default class EntryAbility extends UIAbility {
在entry内新建一个ServiceModule.ts,专用于执行业务逻辑
```
ts
import
{
GlobalContext
}
from
'
../TheServiceExtension
'
import
common
from
'
@ohos.app.ability.common
'
;
import
{
GlobalContext
}
from
'
../GlobalContext
'
;
export
default
class
ServiceModel
{
moduleName
:
string
=
''
;
...
...
@@ -122,7 +127,8 @@ export default class ServiceModel {
return
;
}
this
.
moduleName
=
GlobalContext
.
getContext
().
getObject
(
'
ExtensionContext
'
).
currentHapModuleInfo
.
name
;
let
extensionContext
=
GlobalContext
.
getContext
().
getObject
(
'
ExtensionContext
'
)
as
common
.
ServiceExtensionContext
;
this
.
moduleName
=
extensionContext
.
currentHapModuleInfo
.
name
;
// 根据moduleName执行不同的业务逻辑,实现对不同性能设备的区分
switch
(
this
.
moduleName
)
{
case
'
highPerformance
'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录