Skip to Content
Technical Articles
Author's profile photo Qiang Zhang

New API to Start Flows in The Flows Component of SAP BTP SDK for Android

Introduction

SAP BTP SDK for Android version 3.4 is an important release, it contains many new features, enhancements, and bug fixes. Among the new features, we’d like to emphasize the new API to start a flow here in this blog.

Deprecated APIs to Start Flows

Before SAP BTP SDK for Android 3.4, we have the following 2 APIs to start flows, one to start flows from an activity, another from a fragment.

fun start(activity: Activity, flowContext: FlowContext) {…}
fun start(fragment: Fragment,flowContext: FlowContext) {…}

With these 2 APIs, the client code needs to override onActivityResult to monitor the flow finish status.

There are some drawbacks of the above approach. For example, the logic to start a flow and monitor the finish status would be separated into different places, and if one activity would start more than one flow, the client code needs to use different request codes to start each flow and check the request codes inside onActivityResult.

And for the security considerations, usually the passcode policy would be enabled, then if the mobile app is put into background for a certain period, it needs to unlocked first when being brought back up to foreground again.

In this case, TIMEOUT_UNLOCK flow will be started by the SDK with the topmost activity before being put into background. Since the client code cannot override onActivityResult for every activity in the mobile app, the only way to monitor the flow status is having logic inside onFlowFinished in FlowStateListener, then eventually make the logic inside it quite complex and hard to understand.

Besides, Google Android SDK also marked onActivityResult as deprecated, this is another reason that we provide a new API to start flows.

New API to Start Flows

To address the above problems, we introduced the following new API in the version 3.4 of SAP BTP SDK for Android.

typealias FlowActivityResultCallback = (requestCode: Short, resultCode: Int, data: Intent?) -> Unit

fun start(
    activity: Activity,
    flowContext: FlowContext,
    flowActivityResultCallback: FlowActivityResultCallback? = null
) {
…
}

We’d like to emphasize the following things on this new API:

1. The 1st argument is Activity, so if you start flows within a Fragment, you can easily get the hosting activity of the fragment then start the flow.

2. flowActivityResultCallback was designed to have 3 arguments, it has the similar signature as onActivityResult. So with minor changes in onActivityResult, it can be used as the 3rd parameter of the API, as below:

Flow.start(requireActivity(), flowContext, this::onFlowActivityResult)

3. If a flow is started with this new API, onFlowFinished in FlowStateListener will NOT be called for this flow, so onFlowFinished can be used only for the timeout unlock case in client app.

 

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.