Activities

An Activity is a part of an application UI that is responsible for a task. For example, a media player application can have Activities, 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 Activities.

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

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

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

    Exclusive Activity Host

    ../../_images/exclusive-activity-host.gif

    Data-Driven Exclusive Activity Host

    ../../_images/data-driven-exclusive-activity-host.gif
  • Parallel Activity Host can activate more than one of its child Activities at a time. When you activate an Activity, a Parallel Activity Host brings that Activity to the front. In a Parallel Activity Host you can group Activities, to show the groups in the same order that you defined in the Activity tree. When you activate an Activity in a group, a Parallel Activity Host 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 shows the Activities in order of activation. See Parallel Activity Host.

    ../../_images/parallel-activity-host.gif

You can add Activities to an Activity Host in real-time. This enables you to use the Kanzi Engine API to generate Activities or to add to the application another application for which the structure of Activities 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 together enable you to create a UI that the 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 Activities 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 Activities, Data-Driven Exclusive Activity Hosts, Exclusive Activity Hosts, and Parallel Activity Hosts to form the navigation graph. Activities define the content elements and Activity Hosts define the navigation pattern in your application UI. In each Activity Host, use Activities to create UI content within applications that an Activity Host represents. For example, with Activity Host and Activities 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 Hosts to activate and deactivate Activities:

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

  • When an Activity 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 Activities

Each Activity has the Activity Status property that 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 instantiates the Activity prefab. When you deactivate an Activity, its Activity Host removes the Activity prefab from the node tree.

You can use the Is Initially Active property to set which Activity in an Exclusive Activity Host or Parallel Activity Host is active at application startup.

However, only one Activity can be active at a time in a Data-Driven Exclusive Activity Host and Exclusive Activity Host.

When one Activity (Activity A) is active and you decide to activate another Activity (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 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 Activities

For each Activity you can define properties that are specific to that Activity. For example, an Activity 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 Activities 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 is available, all the child Activities of that Activity Host are available so that you can activate them. However, only the content of the Activities 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.