Activity nodes

An Activity node is 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. 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.

An Activity Host node defines the rules for when its Activity nodes are active. Kanzi has these Activity Host nodes:

  • Data-Driven Exclusive Activity Host and Exclusive Activity Host nodes can have only one of its child Activity nodes active at a time. When one child Activity node of a Data-Driven Exclusive Activity Host or an Exclusive Activity Host node is active, all other Activity nodes of that Activity Host node are inactive.

    For example, you can use a Data-Driven Exclusive Activity Host or an Exclusive Activity Host node to toggle between views in your application. See Exclusive Activity Host nodes and Data-Driven Exclusive Activity Host nodes.

  • Parallel Activity Host node can activate more than one of its child Activity nodes at a time. When you activate an Activity node, a Parallel Activity Host node brings that Activity to the front. In a Parallel Activity Host node you can group Activity nodes, to show the groups in the same order that you defined in the node tree. When you activate an Activity node in a group, a Parallel Activity Host node brings to the front the Activity in that group.

    For example, this way you can implement the showing of critical messages, such as engine failure, in front of regular notifications, such as a phone call notification. In both groups a Parallel Activity Host node shows the Activity nodes in order of activation. See Parallel Activity Host nodes.

You can add Activity nodes to an Activity Host node in real-time. This enables you to use the Kanzi Engine API to generate Activity nodes or to add to the application another application for which the structure of Activity nodes is not known until you run the application. For example, you can use the Kanzi Engine API to generate a large number of menu pages that you want to show to the user.

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 a 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. For example, with Activity Host and Activity nodes you can organize your UI to show different views in your application, such as media player, contacts, and phone view, and to show content in popup windows.

Use the 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 Using the Content Layout nodes.

Status management of Activity nodes

Each Activity node has the Activity Status property which indicates the status of that Activity. When an Activity becomes active or inactive, the Activity Status property changes and in your application you can react to these changes. When you activate an Activity node, its Activity Host node instantiates the Activity prefab. When you deactivate an Activity node, its Activity Host node removes the Activity prefab from the node tree. 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:

  1. 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.

  2. 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.

  3. Activity A becomes inactive. Kanzi virtualizes the properties of Activity A.

  4. Activity B goes to exclusive activation.

Data and logic programming of Activity nodes

For each Activity node you can define properties that are specific to that Activity node. For example, an 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 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 unvirtualizes that Activity, it deserializes the state of that Activity and restores its property values. See Programming Activity nodes with Code Behind.

Virtualization

The main goal of Activity virtualization is to enable you to manage the memory consumption in your application. The navigation graph of the entire application can be large, which is why loading and keeping in memory the UI and assets of an application at all times is rarely feasible. When an Activity Host node is available, all the child Activity nodes of that Activity Host node are available so that you can activate them. However, only the content of the Activity nodes that you activate is loaded and visible, because only a part of the UI is needed at a time. You can configure each Activity prefab how you want to manage the memory it consumes.

When you activate a visual Activity, the Activity Host of that Activity dynamically loads the prefab and asynchronously loads the content of the prefab of that Activity. When an Activity is not active, that Activity prefab is not attached to the node tree.