自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

HarmonyOS中實現(xiàn)頁面跳轉(zhuǎn)的方法匯總

系統(tǒng) OpenHarmony
文章由鴻蒙社區(qū)產(chǎn)出,想要了解更多內(nèi)容請前往:51CTO和華為官方戰(zhàn)略合作共建的鴻蒙技術(shù)社區(qū)https://harmonyos.51cto.com

[[399885]]

想了解更多內(nèi)容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

 –1. 不同Slice間跳轉(zhuǎn),同一個Ability中,優(yōu)點是方便,高效,缺點是業(yè)務(wù)邏輯復(fù)雜度受限;

  1. button.setClickedListener( 
  2.     listener -> present(new SecondAbilitySlice(), new Intent()) 
  3. ); 

 –2. 使用Intent借助于ElementName,最常用的頁面跳轉(zhuǎn)方式,方便傳遞參數(shù)以及實現(xiàn)相對復(fù)雜的業(yè)務(wù)邏輯交互;

  1. ElementName elementName = new ElementName(……); 
  2. intent.setElement(elementName); 
  3. intent.setParam(……); 
  4. startAbility(intent); 

 –3. 借助于Operation,可實現(xiàn)跨應(yīng)用頁面跳轉(zhuǎn);

  1. Intent intent = new Intent(); 
  2. Operation operation = new Intent.OperationBuilder() 
  3.         .withDeviceId(""
  4.         .withBundleName("com.demoapp"
  5.         .withAbilityName("com.demoapp.FooAbility"
  6.         .build(); 
  7.  intent.setOperation(operation); 
  8. startAbility(intent); 

 –4. Rout路由(JS),調(diào)用router.push()接口將uri指定的頁面添加到路由棧中,即跳轉(zhuǎn)到uri指定的頁面。在調(diào)用router方法之前,需要導(dǎo)入router模塊。

調(diào)用router.push()路由到詳情頁;調(diào)用router.back()回到首頁;

  1. // index.js 
  2. import router from '@system.router'
  3. export default { 
  4.   launch() { 
  5.     router.push ({ 
  6.       uri: 'pages/detail/detail'
  7.     }); 
  8.   }, 

  1. // detail.js 
  2. import router from '@system.router'
  3. export default { 
  4.   launch() { 
  5.     router.back(); 
  6.   }, 

 –5. 通過遷移實現(xiàn)分布式設(shè)備間頁面?zhèn)鬟f(有請求遷移和請求回遷兩種操作)

1)需實現(xiàn)IAbilityContinuation接口

2)需要權(quán)限

  1. ohos.permission.GET_DISTRIBUTED_DEVICE_INFO:用于允許獲取分布式組網(wǎng)內(nèi)的設(shè)備列表和設(shè)備信息 
  2. ohos.permission.DISTRIBUTED_DATASYNC:用于允許不同設(shè)備間的數(shù)據(jù)交換 
  3. ohos.permission.DISTRIBUTED_DEVICE_STATE_CHANGE:用于允許監(jiān)聽分布式組網(wǎng)內(nèi)的設(shè)備狀態(tài)變化 
  4. ohos.permission.READ_USER_STORAGE:讀取存儲卡中的內(nèi)容 
  5. ohos.permission.WRITE_USER_STORAGE:修改或刪除存儲卡中的內(nèi)容 
  6. ohos.permission.GET_BUNDLE_INFO:用于查詢其他應(yīng)用的信息 
  7. ohos.permission.servicebus.ACCESS_SERVICE:分布式數(shù)據(jù)傳輸?shù)臋?quán)限 
  8. com.huawei.hwddmp.servicebus.BIND_SERVICE:系統(tǒng)應(yīng)用使用權(quán)限 

 3)需要獲取分布式設(shè)備ID(NetworkID)

核心服務(wù)類:IContinuationRegisterManager

服務(wù)類的常用API方法:

getContinuationRegisterManager();獲取服務(wù)類的對象

register();注冊服務(wù)

showDeviceList();獲取設(shè)備列表

unregister();注銷服務(wù)

4)請求遷移關(guān)鍵步驟(假定設(shè)備A向設(shè)備B遷移)

需要遷移的page實現(xiàn)IAbilityContinuation接口

復(fù)寫onStartContinuation()方法,做遷移前的準(zhǔn)備工作

復(fù)寫onSaveData()方法,保存遷移數(shù)據(jù)

在設(shè)備B上復(fù)寫onRestoreData()方法,恢復(fù)遷移數(shù)據(jù)

在設(shè)備A上復(fù)寫onCompleteContinuation()方法,做遷移后的收尾工作

調(diào)用continueAbility()或continueAbilityReversibly()發(fā)起遷移

5)請求回遷需在設(shè)備A上調(diào)用reverseContinueAbility()請求回遷

以下關(guān)鍵步驟類似4)

想了解更多內(nèi)容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

 

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2009-12-24 17:57:53

WPF頁面跳轉(zhuǎn)

2009-07-03 17:24:31

Servlet頁面跳轉(zhuǎn)

2015-05-05 10:51:32

php頁面跳轉(zhuǎn)方法

2009-12-16 17:24:26

Ruby on Rai

2009-12-02 19:42:24

PHP頁面自動跳轉(zhuǎn)

2009-12-02 20:02:18

PHP實現(xiàn)頁面跳轉(zhuǎn)

2009-07-02 09:25:41

JSP實現(xiàn)頁面跳轉(zhuǎn)

2010-08-05 09:39:17

Flex頁面跳轉(zhuǎn)

2010-08-13 13:25:53

Flex頁面跳轉(zhuǎn)

2011-05-11 16:54:49

JSP

2009-07-03 17:48:24

JSP頁面跳轉(zhuǎn)

2012-04-19 16:41:24

Titanium視頻實現(xiàn)頁面跳轉(zhuǎn)

2010-08-06 09:28:53

Flex頁面跳轉(zhuǎn)

2009-12-02 19:08:19

PHP跳轉(zhuǎn)代碼

2009-02-17 10:40:26

頁面跳轉(zhuǎn)JSP教程

2010-08-05 09:33:08

Flex頁面跳轉(zhuǎn)

2010-05-11 16:55:12

Windows Pho

2009-12-11 13:25:01

PHP頁面跳轉(zhuǎn)

2021-06-22 16:40:32

鴻蒙HarmonyOS應(yīng)用

2021-09-18 14:45:26

鴻蒙HarmonyOS應(yīng)用
點贊
收藏

51CTO技術(shù)棧公眾號