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.
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.
The fragment integration is very straight forward and it's basically divided into 2 steps: Attaching the fragment and receiving a result.
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.
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
The activity integration is very straight forward too. It's basically divided into 2 steps: Starting the activity and receiving a result.
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,
)
)
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
| Props | Required | Description |
|---|---|---|
flowId | Yes | Flow id used in events. |
initialInstruction | Yes | How 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. |
flowConfigOverrides | No | Override global network configurations. Can be used to set specific base url or headers for certain flows. |