Exclusive Activity Host nodes

Exclusive Activity Host nodes can have only one of its child Activity nodes active at a time. When one child Activity node of an Exclusive Activity Host node is active, all other Activity nodes of that Activity Host node are inactive. For example, you can use a an Exclusive Activity Host node to toggle between views in your application.

Using Exclusive Activity Host nodes

To use an Exclusive Activity Host node:

  1. In the main menu select Window > Activity Browser.

    ../../_images/activity-browser-main-menu.png
  2. In the Activity Browser click add-button and create the root Exclusive Activity Host node.

    Kanzi Studio creates an Exclusive Activity Host node in the RootPage node.

    ../../_images/activity-browser-create-root-eah.png ../../_images/node-tree-root-eah.png
  3. In the Activity Browser below the root Exclusive Activity Host node click add-button to create an Activity node and create or assign a prefab to that Activity node.

    For example, create Activity nodes named Media, Navigation, and Phone. For each Activity node use the same name for the Activity prefab.

    Kanzi Studio creates Activity nodes, assigns them to the Exclusive Activity Host node, and for each Activity node creates a prefab in the Prefabs.

    ../../_images/create-activity-and-prefab.png ../../_images/eah-media-navigation-phone-activity-browser.png ../../_images/eah-media-navigation-phone-w-o-content.png
  4. Create a property type that you use in the Activity Host as a Controller Property property:

    1. In the Activity Browser right-click the Exclusive Activity Host node, select Create Controller Property, and then select the data type for the property type.

      An Activity Host node uses the Controller Property property to set and control which Activity node in that Activity Host node is active. To change the state of an Activity node, you can also use any Trigger with the Activate Activity Message or a Data Trigger with the Apply Activation Action.

      For example, select Create Controller Property > Enum to create a property type with the enumeration data type.

      ../../_images/create-controller-property-enum.png
    2. Name the property type, and click OK.

      For example, name the property type MyActivities.

      ../../_images/create-controller-property.png

      Kanzi Studio:

      • Creates the property type.

        When you create a property type with the enumeration data type, Kanzi Studio creates a property type with enumeration keys with the names from the Activity nodes from that Activity Host node.

        ../../_images/library-property-types-myactivities.png ../../_images/create-activityconcept-property.png
      • In the Activity Host node adds the created property type and sets the Controller Property property to the created property type.

        To set which Activity node is active in this Activity Host node, in the Activity Host node you can set the value of the created property type.

        ../../_images/properties-exclusive-activities-host-controlling-property.png
  5. In the Prefabs add content to each Activity node prefab.

    For example, in each Activity node create a Text Block 2D node with the name of that Activity.

    ../../_images/activities-prefabs.png
  6. In the Activity Browser in the Activity that you want to activate, click activate.

    The Activity Browser simulates the activation of Activity nodes in your application. To activate Activity nodes in your Kanzi application, use triggers and actions.

    ../../_images/activity-browser-navigation-activate.png

Activating Activity nodes

You can activate an Activity node in these ways:

Finding out whether an Activity node is active

To find out whether an Activity node is active:

  • Check the value of the Activity Status property for that Activity node.

  • Check the value of the Controller Property property in the Exclusive Activity Host node for that Activity node.

Activating an Activity node with the Activate Activity action

Use the Activate Activity action when:

  • The condition for activating an Activity is too complex to be expressed with the value of a property

  • You do not know in advance the number of Activity nodes in an Activity Host node

To activate an Activity node with the Activate Activity action:

  1. Create an Activity Host node with several Activity nodes the activation state of which you can control with the Controller Property.

    ../../_images/eah-media-navigation-phone.png ../../_images/eah-media-navigation-phone-activity-browser.png
  2. Create a node with a trigger that you want to use to activate an Activity node.

    For example, create a Button node and use the Button: Click trigger.

    ../../_images/activate-project-button.png ../../_images/node-components-button-click.png
  3. In the Node Tree select the node that you created in the previous step, in the Node Components > Triggers press Alt and right-click the trigger that you want to use to activate an Activity node, select Dispatch Message Action > Activate Activity action, and in the action set:

    • Target Item to the Activity Host node that contains the Activity node that you want to activate.

    • Activation Path to the path from the Activity Host node to the Activity node that you want to activate.

      If you nest Activity nodes in other types of nodes, include in the path only the ancestor Activity nodes.

      Tip

      To get the full path to an Activity node, in the Activity Browser right-click an Activity node and select Copy Activation Path. This command copies the entire path from the top-level Activity Host node to that Activity node.

      ../../_images/activity-browser-copy-activation-path.png
    ../../_images/add-activate-activity-action.png ../../_images/activate-activity-configure.png

Activating an Activity node with the Set Property action

Use the Set Property action to activate Activity nodes when the logic of your application relies on the value of the Controller Property property to activate an Activity node.

To activate an Activity node with the Set Property action:

  1. Create an Activity Host node with several Activity nodes the activation state of which you can control with the Controller Property.

    ../../_images/eah-media-navigation-phone.png ../../_images/eah-media-navigation-phone-activity-browser.png
  2. Create a node with a trigger that you want to use to activate an Activity node.

    For example, create a Button node and use the Button: Click trigger.

    ../../_images/activate-project-button.png ../../_images/node-components-button-click.png
  3. In the Node Tree select the node that you created in the previous step, in the Node Components > Triggers press Alt and right-click the trigger that you want to use to activate an Activity node, select the Set Property action, and in the action set:

    • Target Item to the Activity Host node that contains the Activity node that you want to activate.

    • Target Property to the property type that you set in the Activity Host in the Controller Property property.

    • Fixed Value to the value of the Controller Property property that you use in the Activity that you want to activate.

    ../../_images/add-set-property.png ../../_images/set-property-configure.png

Activating the next or previous Activity node

To activate the next or previous Activity node:

  1. Create an Activity Host node with several Activity nodes the activation state of which you can control with the Controller Property.

    ../../_images/eah-media-navigation-phone.png ../../_images/eah-media-navigation-phone-activity-browser.png
  2. Create a node with a trigger that you want to use to activate an Activity node.

    For example, create a Button node and use the Button: Click trigger.

    ../../_images/next-previous-project-button.png ../../_images/node-components-button-click.png
  3. In the Node Tree select the node that you created in the previous step, in the Node Components > Triggers press Alt and right-click the trigger that you want to use to activate an Activity node, select either Navigate To Next Activity or Navigate To Previous Activity action, and in the action set:

    • Target Item to the Activity Host node that contains the Activity nodes that you want to activate.

    • (Optional) If you want the Activity Host node to activate the first or last Activity node when you set off the trigger after you reach the last or first Activity node in that Activity Host node, set the Loop Activity property to enabled.

    ../../_images/add-next-activity-action.png ../../_images/next-activity-configure.png

Using the Activity nodes in the API

For details, see the Activity2D, Activity3D, ExclusiveActivityHost2D, and ExclusiveActivityHost3D classes in the Kanzi Engine API reference.