C

ActivityView QML Type

QML wrapper for Qt Android Activity View. More...

Import Statement: import QtAndroidActivityView
Since: Qt 6.3

Properties

Methods

Detailed Description

ActivityView allows embedding and handling Android apps and activities from a QML component.

Example Usage

The following snippet shows the simplest usage of the ActivityView type.

import QtAndroidAutomotive.ActivityView

ActivityView {
    anchors.fill: parent

    packageName: "com.android.deskclock"
}

Property Documentation

className : QString

This property holds the name of the class inside of the package defined by the packageName property. When defined, the specified class is used to start the activity, otherwise the default class for given package is used, appropriate to launch a main activity in a package.

The name of the class must be specified using the full package destination:

ActivityView {
    anchors.fill: parent

    packageName: "com.android.contacts"
    className: "com.android.contacts.activities.LicenseActivity"
}

However, if the first character in the className property value is a period, the app's package name (packageName property) is prefixed to the name. Therefore, the following example runs the same activity as the example above:

ActivityView {
    anchors.fill: parent

    packageName: "com.android.contacts"
    className: ".activities.LicenseActivity"
}

See also packageName.


packageName : QString

This property holds the name of the package of the Activity that is intended to be run inside the component.

The Activity resolved by the provided packageName and className must meet certain criteria. Check out Known issues and limitations section for details.

See also className.


placeholder : Item

This property holds the placeholder item to be displayed instead of the activity.

The example below demonstrates how to use the placeholder when the ActivityView is moved:

Rectangle {
    width: 400
    height: 600
    border.width: 1

    MouseArea {
        id: dragMouseArea

        anchors.fill: parent
        drag.target: parent
    }

    ActivityView {
        id: activityView

        anchors.fill: parent
        anchors.margins: 30

        packageName: "com.android.deskclock"
        usePlaceholder: dragMouseArea.pressed

        placeholder: Item {
            Image {
                anchors.centerIn: parent
                source: "icon.png"
                width: 50
                height: 50
            }
        }
    }
}

Note: The content item is automatically positioned and resized to fit within the ActivityView. Bindings to the x, y, width, and height properties of the contentItem are not respected.

See also usePlaceholder.


radius : QString

This property holds the corner radius of the ActivityView, in pixels. The same radius is used by all 4 corners.

An additional rectangle with the same radii can be used to create a frame around the ActivityView:

Rectangle {
    anchors.fill: parent
    radius: 20

    ActivityView {
        anchors.fill: parent
        anchors.margins: 1
        radius: 20

        packageName: "com.android.contacts"
    }
}

restoreOnAppResume : bool

This property holds whether the embedded activity should be restored in case it was closed or run somewhere else during app's non-active state. By default this is true.


[read-only] status : enumeration

This property holds the status of the controlled ActivityView.

ConstantDescription
ActivityView.NotInitializedThe component instance is not yet initialized. Initialization is in progress and must complete before any activity can run. This process involves allocating the appropriate resources, such as creating a Surface. Initialization is done once for each instance of the ActivityView component.
ActivityView.ReadyThe component instance is initialized, but valid package/class names are not set. After setting a valid package/class name, the activity will be launched immediatelly.
ActivityView.StartingThe activity defined by package/class names is currently being started.
ActivityView.StartedThe activity has been started.
ActivityView.RemovedExternally (since Qt 6.4)The activity has has been removed from this ActivityView. This happens whenever the app is active and the activity has been run somewhere else or closes. Second case is when the app is not active (suspended ,for example), restoreOnAppResume is set to false and the activity is run somewhere elseor closes.

Use this status to provide an update or respond to the status change in some way. For example, you could bind to the status value:

BusyIndicator {
    running: activityView.status !== ActivityView.Started
}

usePlaceholder : bool

This property holds whether the placeholder is displayed instead of the actual ActivityView. By default this is false.

See also placeholder.


Method Documentation

void restore()

This function reloads the activity that was removed externally from the ActivityView component.

See also restoreOnAppResume and status.


Available under certain Qt licenses.
Find out more.