AbilityStage - 比特日记
AbilityStage
specified
复制成功
复制成功
1
2
3
4
5
6
7
8
9
10
1{
2 "name": "DocumentAbility",
3 "srcEntry": "./ets/documentability/DocumentAbility.ets",
4 "description": "$string:DocumentAbility_desc",
5 "icon": "$media:layered_image",
6 "label": "$string:DocumentAbility_label",
7 'launchType': "specified",
8 "startWindowIcon": "$media:startIcon",
9 "startWindowBackground": "$color:start_window_background"
10}
{
"name": "DocumentAbility",
"srcEntry": "./ets/documentability/DocumentAbility.ets",
"description": "$string:DocumentAbility_desc",
"icon": "$media:layered_image",
"label": "$string:DocumentAbility_label",
'launchType': "specified",
"startWindowIcon": "$media:startIcon",
"startWindowBackground": "$color:start_window_background"
}
复制成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
1import { common, Want } from '@kit.AbilityKit';
2
3@Entry
4@Component
5struct Page06_Document {
6 @State message: string = '备忘录页面';
7 @State docs: Array<number> = []
8 @State index: number = 1
9
10 build() {
11 Column() {
12 Text(this.message)
13 .id('Page06_DocumentHelloWorld')
14 .fontSize($r('app.float.page_text_font_size'))
15 .fontWeight(FontWeight.Bold)
16 .alignRules({
17 center: { anchor: '__container__', align: VerticalAlign.Center },
18 middle: { anchor: '__container__', align: HorizontalAlign.Center }
19 })
20 .onClick(() => {
21 this.message = 'Welcome';
22 })
23
24 Button('新建备忘录').onClick((event: ClickEvent) => {
25 this.docs.push(this.index)
26 let context = getContext(this) as common.UIAbilityContext
27 let want: Want = {
28 deviceId: '',
29 bundleName: 'com.example.snailmall',
30 abilityName: 'DocumentAbility'
31 }
32
33 context.startAbility(want, (err) => {
34 if (err) {
35 console.log('startAbility DocumentAbility failed' + err.message)
36 }
37 }
38
39 )
40 })
41
42 Column() {
43 List() {
44 ForEach(this.docs, (item: number, index: number) => {
45 ListItem() {
46 Row() {
47 Image($r('app.media.startIcon'))
48 .width(30)
49 Text('备忘录:' + item)
50 }
51 }
52 }, (item: number) => item.toString())
53 }
54 }
55 }
56 .height('100%')
57 .width('100%')
58 }
59}
import { common, Want } from '@kit.AbilityKit';
@Entry
@Component
struct Page06_Document {
@State message: string = '备忘录页面';
@State docs: Array<number> = []
@State index: number = 1
build() {
Column() {
Text(this.message)
.id('Page06_DocumentHelloWorld')
.fontSize($r('app.float.page_text_font_size'))
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.onClick(() => {
this.message = 'Welcome';
})
Button('新建备忘录').onClick((event: ClickEvent) => {
this.docs.push(this.index)
let context = getContext(this) as common.UIAbilityContext
let want: Want = {
deviceId: '',
bundleName: 'com.example.snailmall',
abilityName: 'DocumentAbility'
}
context.startAbility(want, (err) => {
if (err) {
console.log('startAbility DocumentAbility failed' + err.message)
}
}
)
})
Column() {
List() {
ForEach(this.docs, (item: number, index: number) => {
ListItem() {
Row() {
Image($r('app.media.startIcon'))
.width(30)
Text('备忘录:' + item)
}
}
}, (item: number) => item.toString())
}
}
}
.height('100%')
.width('100%')
}
}
复制成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1@Entry
2@Component
3struct Page06_Edit {
4 @State message: string = '编辑备忘录';
5
6 build() {
7 Column() {
8 Text(this.message)
9 .id('Page06_EditHelloWorld')
10 .fontSize($r('app.float.page_text_font_size'))
11 .fontWeight(FontWeight.Bold)
12 .alignRules({
13 center: { anchor: '__container__', align: VerticalAlign.Center },
14 middle: { anchor: '__container__', align: HorizontalAlign.Center }
15 })
16 .onClick(() => {
17 this.message = 'Welcome';
18 })
19
20 TextInput({
21 placeholder: '请输入编辑内容'
22 })
23 }
24 .height('100%')
25 .width('100%')
26 }
27}
@Entry
@Component
struct Page06_Edit {
@State message: string = '编辑备忘录';
build() {
Column() {
Text(this.message)
.id('Page06_EditHelloWorld')
.fontSize($r('app.float.page_text_font_size'))
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.onClick(() => {
this.message = 'Welcome';
})
TextInput({
placeholder: '请输入编辑内容'
})
}
.height('100%')
.width('100%')
}
}
配置AbilityStage容器
module.json5
复制成功
1
2
3
4
5
6
7
1{
2 "module": {
3 "name": "default",
4 "type": "entry",
5 "description": "$string:module_desc",
6 'srcEntry': './ets/myabilitystage/MyAbilityStage.ets',
7....
{
"module": {
"name": "default",
"type": "entry",
"description": "$string:module_desc",
'srcEntry': './ets/myabilitystage/MyAbilityStage.ets',
....
复制成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
1import { common, Want } from '@kit.AbilityKit';
2
3@Entry
4@Component
5struct Page06_Document {
6 @State message: string = '备忘录页面';
7 @State docs: Array<number> = []
8 @State index: number = 1
9
10 build() {
11 Column() {
12 Text(this.message)
13 .id('Page06_DocumentHelloWorld')
14 .fontSize($r('app.float.page_text_font_size'))
15 .fontWeight(FontWeight.Bold)
16 .alignRules({
17 center: { anchor: '__container__', align: VerticalAlign.Center },
18 middle: { anchor: '__container__', align: HorizontalAlign.Center }
19 })
20 .onClick(() => {
21 this.message = 'Welcome';
22 })
23
24 Button('新建备忘录').onClick((event: ClickEvent) => {
25 this.docs.push(this.index)
26 let context = getContext(this) as common.UIAbilityContext
27 let want: Want = {
28 deviceId: '',
29 bundleName: 'com.example.snailmall',
30 abilityName: 'DocumentAbility',
31 parameters: {
32 instanceKey: `idx_${this.index++}`
33 }
34 }
35
36 context.startAbility(want, (err) => {
37 if (err) {
38 console.log('startAbility DocumentAbility failed' + err.message)
39 }
40 }
41
42 )
43 })
44
45 Column() {
46 List() {
47 ForEach(this.docs, (item: number, index: number) => {
48 ListItem() {
49 Row() {
50 Image($r('app.media.startIcon'))
51 .width(30)
52 Text('备忘录:' + item)
53 .onClick(() => {
54 let context = getContext(this) as common.UIAbilityContext
55 let want: Want = {
56 deviceId: '',
57 bundleName: 'com.example.snailmall',
58 abilityName: 'DocumentAbility',
59 parameters: {
60 instanceKey: `idx_${index + 1}`
61 }
62 }
63 context.startAbility(want, (err) => {
64 if (err) {
65 console.log('startAbility DocumentAbility failed' + err.message)
66 }
67 })
68 })
69 }
70 }
71 }, (item: number) => item.toString())
72 }
73 }
74 }
75 .height('100%')
76 .width('100%')
77 }
78}
import { common, Want } from '@kit.AbilityKit';
@Entry
@Component
struct Page06_Document {
@State message: string = '备忘录页面';
@State docs: Array<number> = []
@State index: number = 1
build() {
Column() {
Text(this.message)
.id('Page06_DocumentHelloWorld')
.fontSize($r('app.float.page_text_font_size'))
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.onClick(() => {
this.message = 'Welcome';
})
Button('新建备忘录').onClick((event: ClickEvent) => {
this.docs.push(this.index)
let context = getContext(this) as common.UIAbilityContext
let want: Want = {
deviceId: '',
bundleName: 'com.example.snailmall',
abilityName: 'DocumentAbility',
parameters: {
instanceKey: `idx_${this.index++}`
}
}
context.startAbility(want, (err) => {
if (err) {
console.log('startAbility DocumentAbility failed' + err.message)
}
}
)
})
Column() {
List() {
ForEach(this.docs, (item: number, index: number) => {
ListItem() {
Row() {
Image($r('app.media.startIcon'))
.width(30)
Text('备忘录:' + item)
.onClick(() => {
let context = getContext(this) as common.UIAbilityContext
let want: Want = {
deviceId: '',
bundleName: 'com.example.snailmall',
abilityName: 'DocumentAbility',
parameters: {
instanceKey: `idx_${index + 1}`
}
}
context.startAbility(want, (err) => {
if (err) {
console.log('startAbility DocumentAbility failed' + err.message)
}
})
})
}
}
}, (item: number) => item.toString())
}
}
}
.height('100%')
.width('100%')
}
}
复制成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1@Entry
2@Component
3struct Page06_Edit {
4 @State message: string = '编辑备忘录';
5
6 build() {
7 Column() {
8 Text(this.message)
9 .id('Page06_EditHelloWorld')
10 .fontSize($r('app.float.page_text_font_size'))
11 .fontWeight(FontWeight.Bold)
12 .alignRules({
13 center: { anchor: '__container__', align: VerticalAlign.Center },
14 middle: { anchor: '__container__', align: HorizontalAlign.Center }
15 })
16 .onClick(() => {
17 this.message = 'Welcome';
18 })
19
20 TextInput({
21 placeholder: '请输入编辑内容'
22 })
23 }
24 .height('100%')
25 .width('100%')
26 }
27}
@Entry
@Component
struct Page06_Edit {
@State message: string = '编辑备忘录';
build() {
Column() {
Text(this.message)
.id('Page06_EditHelloWorld')
.fontSize($r('app.float.page_text_font_size'))
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.onClick(() => {
this.message = 'Welcome';
})
TextInput({
placeholder: '请输入编辑内容'
})
}
.height('100%')
.width('100%')
}
}
复制成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1import { AbilityStage, Want } from "@kit.AbilityKit";
2
3export default class MyAbilityStage extends AbilityStage {
4 // 先执行onCreate,再加载UIAbility
5 onCreate(): void {
6 // 首次加载,module初始化
7 }
8
9 onDestroy(): void {
10 console.log('MyAbilityStage onDestroy')
11 }
12
13 onAcceptWant(want: Want): string {
14 // 仅在specified模式生效
15 if (want.abilityName === 'DocumentAbility') {
16 // idx_1, idx_2
17 return `${want?.parameters?.instanceKey}`
18 }
19 return ''
20 }
21}
import { AbilityStage, Want } from "@kit.AbilityKit";
export default class MyAbilityStage extends AbilityStage {
// 先执行onCreate,再加载UIAbility
onCreate(): void {
// 首次加载,module初始化
}
onDestroy(): void {
console.log('MyAbilityStage onDestroy')
}
onAcceptWant(want: Want): string {
// 仅在specified模式生效
if (want.abilityName === 'DocumentAbility') {
// idx_1, idx_2
return `${want?.parameters?.instanceKey}`
}
return ''
}
}
specified
存在111窗口,则直接打开

Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语
浙ICP备11005866号-12