Qt for HarmonyOS/qtohosextras doc/Application Continuation Example
< Qt for HarmonyOS / qtohosextras doc
Application Continuation Example
Demonstrates cross-device application continuation with distributed data objects and file assets.
The window shows a set of editable fields, the content of a text file asset, a sync progress label, a checkbox controlling whether the source device exits after migration, and buttons that toggle the continuation state with QOhosAbilityContext::setContinuationActive().
On the source device, the continueRequestReceived() signal delivers a QOhosOnContinueContext. The example builds a QOhosDistributedDataObject from the field values with QOhosDistributedDataObject::create(), attaches the text file with addAssets(), and hands the object over with QOhosOnContinueContext::setResponseOnDistributedDataObjectsSaveResults(). When saving succeeded and QOhosOnContinueContext::sourceApplicationVersionCode() matches the local version code, the request is accepted with setAgreeResponse(); otherwise setMismatchResponse() is called. The checkbox state is applied with setExitAppOnSourceDeviceAfterMigration() before the response is delivered.
On the target device, QtOhosExtras::tryGetOnContinueData() and QtOhosExtras::tryRestoreOnContinueDistributedDataObjects() recover the migrated data. The restored object's dataChanged(), statusChanged() and progressChanged() signals keep the fields, the asset view and the progress label up to date.
Note: The window is shown before QOhosAbilityContext::getInstanceForMainWindow() is called, so that a valid QWindow exists. The restored distributed data object handle is kept alive for as long as the fields should stay in sync, and assets are attached before the object joins a distributed session.