• Home
  • Features
  • Spec
  • Guides
  • Sandbox
  • Step Studio
  • Overview
  • Quick start
    • Integrating on Web
    • Integrating on iOS
    • Integrating on Android
  • Writing or editing a flow
  • Working with custom renderers
  • Analytics

Integrating on Android

This page is for Android engineers who want to integrate an existing flow into their product.

These instructions presume that you have the Dynamic Flow renderer system integrated in your app. For the Wise app everything was already done by the Dynamic Flow team.

Install required dependencies on your module

First step to setup a Dynamic Flow is to add the core dependency to your Gradle.build file:

implementation(projects.dynamicFlow.dfCore)

This will allow you to to have access to our DynamicFlowFragment and DynamicFlowActivity, which are our main integration entry points in the Android app.

Integrating a Dynamic Flow Fragment

The fragment integration is very straight forward and it's basically divided into 2 steps: Attaching the fragment and receiving a result.

Attaching the fragment

The Dynamic Flow fragment will be configured by the FlowLaunchArgs:

val flowArgs = FlowLaunchArgs(
    flowId = args.flowId,
    initialInstruction = args.initialInstruction,
    flowConfigOverrides = args.flowConfigOverrides,
)

val fragment = DynamicFlowFragment.newInstance(flowArgs)

childFragmentManager.commit {
    replace(R.id.container, fragment, tag)
}

After this the flow will start and you will just need to collect the result.

Receiving a result

To receive a result you can use an extension function created by the dynamic flow team on your fragment manager, like the example below:

childFragmentManager.registerForDynamicFlowTermination(this) { flowTerminationState ->
    // Handle termination.
}

The 3 possible states for termination are:

  • Success: Flow terminated successfully
  • Failed: Flow terminated with an unexpected error
  • Cancelled: Flow terminated intentionally by user

Integrating a Dynamic Flow Activity

The activity integration is very straight forward too. It's basically divided into 2 steps: Starting the activity and receiving a result.

Starting the activity

The Dynamic Flow activity will be configured by following the example below:

startActivity(
    DynamicFlowActivity.newIntent(
        context = context,
        flowId = args.flowId,
        initialInstruction = args.initialInstruction,
        flowConfigOverrides = args.flowConfigOverrides,
    )
)

Receiving a result

The dynamic flow activity will return an activity result on termination, therefore you can use the standard activity result apis from the Android framework to collect the result. We use the DynamicFlowActivity.EXTRA_TERMINATION_RESULT key to get the result from the bundle.

registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
    val dynamicFlowResult = requireNotNull(
        it.data!!.getParcelableExtra<FlowTerminationState>(DynamicFlowActivity.EXTRA_TERMINATION_RESULT)
    )

    // Handle termination.
}

The 3 possible states for termination are:

  • Success: Flow terminated successfully
  • Failed: Flow terminated with an unexpected error
  • Cancelled: Flow terminated intentionally by user

FlowLaunchArgs properties table

PropsRequiredDescription
flowIdYesFlow id used in events.
initialInstructionYesHow the first step of the flow should be initialized. GET requests, POST requests and generic responses are supported. They all need to follow the DF specification.
flowConfigOverridesNoOverride global network configurations. Can be used to set specific base url or headers for certain flows.