1# @ohos.app.ability.continueManager (Cross-Device Migration) 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 quick start result when an application is launched quickly. This API uses an asynchronous callback to return the result. 20 21> **NOTE** 22> 23> The quick start feature allows the application to start concurrently while the user triggers migration and waits for the migration data to return, reducing wait time. To enable the quick start feature, add the suffix **_ContinueQuickStart** to the **continueType** value in the [module.json5](../../quick-start/module-configuration-file.md) file of the source application. 24 25**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 26 27**Parameters** 28 29 | Name| Type | Mandatory| Description | 30 | -------- |-------------------------------------------------------------------------------------------------| -------- |------------------------------------------| 31 | type | string | Yes| The value is fixed at **prepareContinue**. | 32 | context | [Context](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes| Context of the ability. | 33 | 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.| 34 35**Error codes** 36 37For details about the error codes, see [Distributed Scheduler Error Codes](errorcode-DistributedSchedule.md). 38 39| ID| Error Message| 40| ------- | -------------------------------- | 41| 16300501 | the system ability work abnormally. | 42 43**Example** 44 45 ```ts 46import { AbilityConstant, UIAbility, Want, continueManager } from '@kit.AbilityKit'; 47import { hilog } from '@kit.PerformanceAnalysisKit'; 48 49const TAG: string = '[MigrationAbility]'; 50const DOMAIN_NUMBER: number = 0xFF00; 51 52export default class MigrationAbility extends UIAbility { 53 storage : LocalStorage = new LocalStorage(); 54 55 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 56 hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); 57 58 // 1. Quick start is configured. Trigger the lifecycle callback when the application is launched immediately. 59 if (launchParam.launchReason === AbilityConstant.LaunchReason.PREPARE_CONTINUATION) { 60 // Register the callback to obtain the quick start result. 61 try { 62 continueManager.on("prepareContinue", this.context, (err, continueResultInfo) => { 63 if (err.code != 0) { 64 console.error('register failed, cause: ' + JSON.stringify(err)); 65 return; 66 } 67 console.info('register finished, ' + JSON.stringify(continueResultInfo)); 68 }); 69 } catch (e) { 70 console.error('register failed, cause: ' + JSON.stringify(e)); 71 } 72 // If the application data to migrate is large, add a loading screen here (for example, displaying "loading" on the screen). 73 // Handle issues related to custom redirection and timing. 74 // ... 75 } 76 } 77} 78 ``` 79 80## continueManager.off 81 82off(type: 'prepareContinue', context: Context, callback?: AsyncCallback<ContinueResultInfo>): void 83 84Unregisters the callback used to obtain the quick start result when an application is launched quickly. This API uses an asynchronous callback to return the result. 85 86> **NOTE** 87> 88> The quick start feature allows the application to start concurrently while the user triggers migration and waits for the migration data to return, reducing wait time. To enable the quick start feature, add the suffix **_ContinueQuickStart** to the **continueType** value in the [module.json5](../../quick-start/module-configuration-file.md) file of the source application. 89 90**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 91 92**Parameters** 93 94| Name| Type | Mandatory| Description | 95 | -------- |------------------------------------| -------- |--------------------------------------| 96| type | string | Yes| The value is fixed at **prepareContinue**. | 97| context | [Context](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes| Context of the ability. | 98| callback | AsyncCallback<[ContinueResultInfo](js-apis-app-ability-continueManager.md#continueresultinfo)> | No| 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.| 99 100**Error codes** 101 102For details about the error codes, see [Distributed Scheduler Error Codes](errorcode-DistributedSchedule.md). 103 104| ID | Error Message| 105|----------| -------------------------------- | 106| 16300501 | the system ability work abnormally. | 107 108**Example** 109 110 ```ts 111import { AbilityConstant, UIAbility, Want, continueManager } from '@kit.AbilityKit'; 112import { hilog } from '@kit.PerformanceAnalysisKit'; 113 114const TAG: string = '[MigrationAbility]'; 115const DOMAIN_NUMBER: number = 0xFF00; 116 117export default class MigrationAbility extends UIAbility { 118 storage : LocalStorage = new LocalStorage(); 119 120 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 121 hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); 122 123 // 1. Quick start is configured. Trigger the lifecycle callback when the application is launched immediately. 124 if (launchParam.launchReason === AbilityConstant.LaunchReason.PREPARE_CONTINUATION) { 125 // Unregister the callback used to obtain the quick start result. 126 try { 127 continueManager.off("prepareContinue", this.context, (err, continueResultInfo) => { 128 if (err.code != 0) { 129 console.error('unregister failed, cause: ' + JSON.stringify(err)); 130 return; 131 } 132 console.info('unregister finished, ' + JSON.stringify(continueResultInfo)); 133 }); 134 } catch (e) { 135 console.error('unregister failed, cause: ' + JSON.stringify(e)); 136 } 137 // If the application data to migrate is large, add a loading screen here (for example, displaying "loading" on the screen). 138 // Handle issues related to custom redirection and timing. 139 // ... 140 } 141 } 142} 143 ``` 144 145## ContinueResultInfo 146 147Describes the quick start result returned by the callback. 148 149**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 150 151| Name| Type | Read-Only| Optional| Description | 152| -------- |-------------------------------------------------------------------------------|----|----|----------| 153| resultState | [ContinueStateCode](js-apis-app-ability-continueManager.md#continuestatecode) | Yes | No | Status code of the operation result.| 154| resultInfo | string | No | Yes | Description of the operation result.| 155 156## ContinueStateCode 157 158Enumerates the status codes of the quick start result. 159 160**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 161 162| Name| Value | Description | 163| -------- |----|-------| 164| SUCCESS | 0 | Operation succeeded.| 165| SYSTEM_ERROR | Others| Operation failed.| 166