1# @ohos.app.ability.continueManager (continueManager) 2 3The continueManager module provides capabilities for managing cross-device application migration. For example, it allows you to obtain the result of quickly launching the target application during the cross-device migration process. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 18. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import { continueManager } from '@kit.AbilityKit'; 13``` 14 15## continueManager.on 16 17on(type: 'prepareContinue', context: Context, callback: AsyncCallback<ContinueResultInfo>): void 18 19Registers a callback to obtain the result of quickly launching the application during the cross-device continuity process. This API uses an asynchronous callback to return the result. 20 21**System capability**: SystemCapability.Ability.DistributedManagementService 22 23**Parameters** 24 25 | Name| Type | Mandatory| Description | 26 | -------- |-------------------------------------------------------------------------------------------------| -------- |------------------------------------------| 27 | type | string | Yes| The value is fixed at **prepareContinue**. | 28 | context | [Context](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes| Context of the ability. | 29 | callback | AsyncCallback<[ContinueResultInfo](js-apis-app-ability-continueManager.md#continueresultinfo)> | Yes| Callback used to return the result. If obtaining the quick start result is successful, **err** is undefined, and **ContinueResultInfo** is the obtained quick startup result. Otherwise, **err** is an error object.| 30 31**Example** 32 33 ```ts 34import { AbilityConstant, UIAbility, Want, continueManager } from '@kit.AbilityKit'; 35import { hilog } from '@kit.PerformanceAnalysisKit'; 36 37const TAG: string = '[MigrationAbility]'; 38const DOMAIN_NUMBER: number = 0xFF00; 39 40export default class MigrationAbility extends UIAbility { 41 storage : LocalStorage = new LocalStorage(); 42 43 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 44 hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); 45 46 // 1. Quick start is configured. Trigger the lifecycle callback when the application is launched immediately. 47 if (launchParam.launchReason === AbilityConstant.LaunchReason.PREPARE_CONTINUATION) { 48 // Register the callback to obtain the quick start result. 49 this.registerQuickStartCallback(); 50 // If the application data to migrate is large, add a loading screen here (for example, displaying "loading" on the screen). 51 // Handle issues related to custom redirection and timing. 52 // ... 53 } 54 } 55 56 async registerQuickStartCallback() : Promise<void>{ 57 continueManager.on("prepareContinue", this.context, (err, continueResultInfo)=>{ 58 if (err.code != 0) { 59 console.error('register failed, cause: ' + JSON.stringify(err)); 60 return; 61 } 62 console.info('register finished, ' + JSON.stringify(continueResultInfo)); 63 }); 64 } 65} 66 ``` 67 68## continueManager.off 69 70off(type: 'prepareContinue', context: Context, callback: AsyncCallback<ContinueResultInfo>): void 71 72Unregisters the callback used to obtain the result of quickly launching the application during the cross-device continuity process. This API uses an asynchronous callback to return the result. 73 74**System capability**: SystemCapability.Ability.DistributedManagementService 75 76**Parameters** 77 78| Name| Type | Mandatory| Description | 79 | -------- |------------------------------------| -------- |--------------------------------------| 80| type | string | Yes| The value is fixed at **prepareContinue**. | 81| context | [Context](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes| Context of the ability. | 82| callback | AsyncCallback<[ContinueResultInfo](js-apis-app-ability-continueManager.md#continueresultinfo)> | Yes| Callback used to return the result. If the callback is unregistered, **err** is undefined, and **ContinueResultInfo** is the callback unregistration result. Otherwise, **err** is an error object.| 83 84**Example** 85 86 ```ts 87import { AbilityConstant, UIAbility, Want, continueManager } from '@kit.AbilityKit'; 88import { hilog } from '@kit.PerformanceAnalysisKit'; 89 90const TAG: string = '[MigrationAbility]'; 91const DOMAIN_NUMBER: number = 0xFF00; 92 93export default class MigrationAbility extends UIAbility { 94 storage : LocalStorage = new LocalStorage(); 95 96 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 97 hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); 98 99 // 1. Quick start is configured. Trigger the lifecycle callback when the application is launched immediately. 100 if (launchParam.launchReason === AbilityConstant.LaunchReason.PREPARE_CONTINUATION) { 101 // Register the callback to obtain the quick start result. 102 this.registerQuickStartCallback(); 103 // If the application data to migrate is large, add a loading screen here (for example, displaying "loading" on the screen). 104 // Handle issues related to custom redirection and timing. 105 // ... 106 } 107 } 108 109 async registerQuickStartCallback() : Promise<void>{ 110 continueManager.off("prepareContinue", this.context, (err, continueResultInfo)=>{ 111 if (err.code != 0) { 112 console.error('register failed, cause: ' + JSON.stringify(err)); 113 return; 114 } 115 console.info('register finished, ' + JSON.stringify(continueResultInfo)); 116 }); 117 } 118} 119 ``` 120 121## ContinueResultInfo 122 123Describes the quick start result returned by the callback. 124 125**System capability**: SystemCapability.Ability.DistributedManagementService 126 127| Name| Type | Read-Only| Optional| Description | 128| -------- |-------------------------------------------------------------------------------|----|----|----------| 129| resultState | [ContinueStateCode](js-apis-app-ability-continueManager.md#continuestatecode) | Yes | No | Status code of the operation result.| 130| resultInfo | string | No | Yes | Description of the operation result.| 131 132## ContinueStateCode 133 134Enumerates the status codes of the quick start result. 135 136**System capability**: SystemCapability.Ability.DistributedManagementService 137 138| Name| Value | Description | 139| -------- |----|-------| 140| SUCCESS | 0 | Operation succeeded.| 141| SYSTEM_ERROR | Others| Operation failed.| 142