Class Activity2D

Class Hierarchy

An Activity is a part of application UI that is responsible for a task. For example, a media player application can have Activity nodes, such as radio, music player, and AUX. However, an Activity can also be a smaller task, such as an Activity for the popup volume indicator that appears only when the user changes the volume in a media player. An Activity can be visual, but does not have to be. For example, an Activity that is visual can instantiate a prefab to show a popup window, while an Activity that is not visual can be music playback which plays music in the background regardless of other Activity nodes.

Application UI structure and navigation The Activity, Data-Driven Exclusive Activity Host, Exclusive Activity Host, and Parallel Activity Host nodes together enable you to create the UI that user can navigate in your application. You implement the navigation as a reaction to user interaction or changes to data coming to the application, by activating and deactivating Activity nodes to switch application views and to show different application layers, such as popup windows. That way you can control which parts of your application UI the user can see and interact with.

Use the Activity, Data-Driven Exclusive Activity Host, Exclusive Activity Host, and Parallel Activity Host nodes to form the navigation graph. Activity nodes define the content elements and the Activity Host nodes define the navigation pattern in your application UI. In each Activity Host node, use Activity nodes to create UI content within applications that an Activity Host represents. When you use these nodes in your application, you navigate application UI by sending to the Activity Host node the address of the Activity node to which you want to navigate. For example, with Activity Host and Activity nodes you can organize your UI to show a different views in your application, such as media player, contacts, and phone view, and to show content in popup windows.

Use Activity Host nodes to activate and deactivate Activity nodes:

  • When an Activity node is active, the Activity prefab is attached to the node tree, is visible, and the user can interact with its content.
  • When an Activity node is inactive, the Activity prefab is not attached to the node tree, is not visible, and the user cannot interact with its content.

The Activity and Activity Host nodes inherit from the ContentLayout class to lay out their content like a Content Layout node. See ContentLayout2D and ContentLayout3D.

See ParallelActivityHost2D, ParallelActivityHost3D, ExclusiveActivityHost2D, and ExclusiveActivityHost3D.

Status management of Activity nodes Each Activity node has the Status property that indicates the status of that Activity. When an Activity becomes active or inactive, the Status property changes and in your application you can react to these changes. You can use the Is Initially Active property to set which Activity node in an Exclusive Activity Host or Parallel Activity Host node is active at application startup. However, only one Activity node can be active at a time in a Data-Driven Exclusive Activity Host and Exclusive Activity Host nodes.

When one Activity node (Activity A) is active and you decide to activate another Activity node (Activity B), this is how the Activity status changes:

  • Activity A goes to exclusive deactivation and, if content of the Activity B prefab is not yet loaded, Activity Host node gets a request to load the Activity B prefab and asynchronously load the content of the Activity B prefab.
  • When the Activity B prefab is loaded, Activity A goes to parallel deactivation. Once Kanzi loads the content of the Activity B prefab, Kanzi instantiates the Activity B prefab and goes into parallel activation.
  • Activity A becomes inactive. Kanzi virtualizes the properties of Activity A.
  • Activity B goes to exclusive activation.

Programming See Code behind.

Creating transitions between Activity nodes You can create transitions for status changes of Activity nodes.

To create transitions between Activity nodes:

  • Create a state manager and set its Controller Property to the Status property.
  • In Activity nodes set the Status Manager property to the state manager that you created in the previous step.
  • Create the states that map to the different statuses of Activity nodes.
  • In the state manager define the transitions that you want to use.

Data and logic programming of Activity nodes For each Activity node you can define properties that are specific to that Activity node. For example, Activity node for a music player can switch music on and off, or change the volume level.

When you create a property for an Activity node, set the namespace of that property to \e ActivityProperty. You can create properties with int, bool, float, and enum data types. If you use code behind for an Activity, Kanzi adds the properties of that Activity to the code behind.

The values of these properties implement the state machine and logic of your Kanzi application, which is why Kanzi preserves the values of these properties even when an Activity is virtual. When Kanzi virtualizes an Activity, it serializes the properties of that Activity and when Kanzi devirtualizes that Activity, it deserializes the state of that Activity and restores its property values.

Code behind Code behind is a workflow where you associate code with an instance of an Activity instead of a type. In Kanzi Studio in the Activity Browser window, you can generate a code behind stub for any Activity node. This stub is associated with that particular Activity and has access to the properties of that Activity. In code behind you can write code that you can associate with the view or controller parts of the model-view-controller pattern. For example, you can:

  • React to Activity status changes.
  • Connect to a remote service when the Activity is activated and save data and disconnect when an Activity is deactivated.
  • Install Kanzi command handlers and define their implementations, such as increase the volume when the user presses a button.
  • Implement complex UI interaction, such as drag-and-drop of data between UI elements.
  • React to changes of status of an Activity.

Virtualization The main goal of Activity virtualization is to manage memory consumption in your application efficiently. Since the navigation graph of the entire application can be large, keeping the UI and assets loaded in memory at all times is rarely feasible.

When you activate an Activity, its Activity Host dynamically loads the prefab and asynchronously loads the required resources. On deactivation, the Activity Host detaches the Activity from the node tree and deletes the Activity instance. However, the acquired resources remain in the memory.

To release the resources of deactivated Activities, call ResourceManager::purge().

Controlling virtualization By default, when you deactivate an Activity, Kanzi serializes the values of Activity properties for that Activity and its child Activities. Besides the values of Activity properties that you add, this includes information about the focus and activation state of Activities. Keep in mind that Kanzi does not serialize the runtime state of other, non-Activity properties.

When you activate a deactivated Activity, Kanzi restores the values of Activity properties for that Activity and its child Activities. When you disable virtualization, Kanzi does not preserve the values of Activity properties.

You can also reset the serialized state of an Activity, before activating or after deactivating that Activity. By default, Kanzi restores the serialized state.

Activity persistence By default, when you deactivate an Activity, Kanzi detaches the Activity from the node tree and deletes the Activity instance. You can set Kanzi to preserve the Activity instance when the Activity is deactivated. When you activate such an Activity again, Kanzi restores the Activity node in the same state as it was before deactivation, even if you disable virtualization for this Activity. This way you can skip Activity instantiation when you activate the Activity again.

Use an Activity 2D to create a part of an application UI that is responsible for a task. For example, a media player application can have Activity nodes, such as radio, music player, and AUX. To define the rules when an Activity node is active, use an Activity Host node.

Inherits properties and message types from Activity2DMetadata.

Synopsis

Methods
create()

Creates a 2D activity node

Activity2D.Activity2D:create(name)

Creates a 2D activity node.

Parameters
name (string)

The name of the node.