SAP

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Create Your Own Flow

Learn how to create your own flow with the framework provided by the Flows component of SAP BTP SDK for Android.

Overview

You will learn

  • ✔How to write a flow step
  • ✔How to write your own flow Besides the pre-defined flows described in the previous tutorials, the Flows Component also provides a framework for client code to create its own flow. Typically a flow consists of several flow steps and also may include other flows as sub-flows. The Flows framework provides flexible ways for client code to create a customized flow:
  • ✔The client code can create its own flow steps and then create a flow with the combination of the steps.
  • ✔The client code can create a flow which only includes the pre-defined flow steps or pre-defined flows as sub-flows without defining its own flow steps.
  • ✔The client code can combine its own flow steps, pre-defined flow steps, its own flows and the pre-defined flows to create a customized flow.
Haoyue Feng H Haoyue Feng August 21, 2026
Created on April 26, 2024
Contributors

More from Haoyue Feng

See all 12 tutorials by Haoyue Feng →

Prerequisites

Steps

Details

You will learn

  • How to write a flow step
  • How to write your own flow

Besides the pre-defined flows described in the previous tutorials, the Flows Component also provides a framework for client code to create its own flow. Typically a flow consists of several flow steps and also may include other flows as sub-flows. The Flows framework provides flexible ways for client code to create a customized flow:

  • The client code can create its own flow steps and then create a flow with the combination of the steps.
  • The client code can create a flow which only includes the pre-defined flow steps or pre-defined flows as sub-flows without defining its own flow steps.
  • The client code can combine its own flow steps, pre-defined flow steps, its own flows and the pre-defined flows to create a customized flow.

Step 1 Write your own flow step
—

  1. A flow step must extend from the parent class com.sap.cloud.mobile.flowv2.core.FlowStepFragment.

  2. A flow step can override the onCreateView function to create UI for the step.

  3. The parent class provides one important helper function for the flow step to notify the framework that it’s done, so the flow framework can move to next step or finish the flow.

    protected fun stepDone(currentStepId: Int, popCurrent: Boolean = false, vararg args: Pair)

  4. The following code snippet creates a simple flow step. First we create a layout XML file named fragment_step1 for the UI part which includes a text view and a button.

    XML
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/fragmentStepOne"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".steps.CustomStepOne">
    
        <TextView
            android:id="@+id/txtStepOne"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
        <Button
            android:id="@+id/btnOKStepOne"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            android:text="@android:string/ok"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/txtStepOne" />
    </androidx.constraintlayout.widget.ConstraintLayout>

Then we can create a flow step with the layout created above. In this flow step, we set a step name, create view with the layout file fragment_step1 and add button click listener to notify step done.

```Java
public class CustomStepOne extends FlowStepFragment {
    @NotNull
    @Override
    public String getStepName() {
        return "Step 1";
    }
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_step1, container, false);
}

@Override public void onActivityCreated(@org.jetbrains.annotations.Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); TextView txtStepOne = this.getView().findViewById(R.id.txtStepOne); txtStepOne.setText(getStepName()); Button btnStepOne = this.getView().findViewById(R.id.btnOKStepOne); btnStepOne.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { stepDone(R.id.fragmentStepOne); } }); }

}

Code
</code></pre>

</div>

<div class="tab-panel" data-tab-panel="1" data-tab-name="Kotlin" hidden> <ol> <li> <p>A flow step must extend from the parent class <strong><code>com.sap.cloud.mobile.flowv2.core.FlowStepFragment</code></strong>.</p> </li> <li> <p>A flow step can override the <strong><code>onCreateView</code></strong> function to create UI for the step.</p> </li> <li> <p>The parent class provides one important helper function for the flow step to notify the framework that it&rsquo;s done, so the flow framework can move to next step or finish the flow.</p> <p><strong><code>protected fun stepDone(currentStepId: Int, popCurrent: Boolean = false, vararg args: Pair)</code></strong></p> </li> <li> <p>The following code snippet creates a simple flow step. First we create a layout XML file named <strong><code>fragment_step1</code></strong> for the UI part which includes a text view and a button.</p> <div class="code-block code-block-long"> <div class="code-block-header"><span class="code-block-lang">XML</span><button type="button" class="code-block-copy" onclick="copyCodeBlock(this)" aria-label="Copy code"> <svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M4 4V1.5C4 1.22 4.22 1 4.5 1H13.5C13.78 1 14 1.22 14 1.5V10.5C14 10.78 13.78 11 13.5 11H11" stroke="currentColor" stroke-width="1.2"/><rect x="2" y="5" width="9" height="10" rx=".5" stroke="currentColor" stroke-width="1.2" fill="none"/></svg> <span class="copy-label">Copy</span> </button> </div> <div class="code-block-body" data-collapsed="true"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-xml" data-lang="xml"><span class="line"><span class="cl"><span class="cp">&lt;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&gt;</span> </span></span><span class="line"><span class="cl"><span class="nt">&lt;androidx.constraintlayout.widget.ConstraintLayout</span> <span class="na">xmlns:android=</span><span class="s">&#34;http://schemas.android.com/apk/res/android&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">xmlns:app=</span><span class="s">&#34;http://schemas.android.com/apk/res-auto&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">xmlns:tools=</span><span class="s">&#34;http://schemas.android.com/tools&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">android:id=</span><span class="s">&#34;@+id/fragmentStepOne&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">android:layout_width=</span><span class="s">&#34;match_parent&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">android:layout_height=</span><span class="s">&#34;match_parent&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">tools:context=</span><span class="s">&#34;.steps.CustomStepOne&#34;</span><span class="nt">&gt;</span> </span></span><span class="line"><span class="cl"> </span></span><span class="line"><span class="cl"> <span class="nt">&lt;TextView</span> </span></span><span class="line"><span class="cl"> <span class="na">android:id=</span><span class="s">&#34;@+id/txtStepOne&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">android:layout_width=</span><span class="s">&#34;wrap_content&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">android:layout_height=</span><span class="s">&#34;wrap_content&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">app:layout_constraintBottom_toBottomOf=</span><span class="s">&#34;parent&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">app:layout_constraintEnd_toEndOf=</span><span class="s">&#34;parent&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">app:layout_constraintStart_toStartOf=</span><span class="s">&#34;parent&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">app:layout_constraintTop_toTopOf=</span><span class="s">&#34;parent&#34;</span> <span class="nt">/&gt;</span> </span></span><span class="line"><span class="cl"> </span></span><span class="line"><span class="cl"> <span class="nt">&lt;Button</span> </span></span><span class="line"><span class="cl"> <span class="na">android:id=</span><span class="s">&#34;@+id/btnOKStepOne&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">android:layout_width=</span><span class="s">&#34;wrap_content&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">android:layout_height=</span><span class="s">&#34;wrap_content&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">android:layout_marginTop=</span><span class="s">&#34;24dp&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">android:text=</span><span class="s">&#34;@android:string/ok&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">app:layout_constraintEnd_toEndOf=</span><span class="s">&#34;parent&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">app:layout_constraintStart_toStartOf=</span><span class="s">&#34;parent&#34;</span> </span></span><span class="line"><span class="cl"> <span class="na">app:layout_constraintTop_toBottomOf=</span><span class="s">&#34;@+id/txtStepOne&#34;</span> <span class="nt">/&gt;</span> </span></span><span class="line"><span class="cl"><span class="nt">&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;</span></span></span></code></pre></div></div><button type="button" class="code-block-toggle" data-action="toggle-code" aria-expanded="false"> <span class="toggle-show">Show all 28 lines</span> <span class="toggle-hide">Show less</span> </button></div> </li> </ol> <p>Then we can create a flow step with the layout created above. In this flow step, we set a step name, create view with the layout file <strong><code>fragment_step1</code></strong> and add button click listener to notify step done.</p> <pre><code>```Kotlin class CustomStepOne : FlowStepFragment() {

override fun getStepName(): String {
    return &amp;quot;Step 1&amp;quot;
}

override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    return inflater.inflate(R.layout.fragment_step1, container, false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
    super.onActivityCreated(savedInstanceState)
    txtStepOne.text = getStepName()
    btnOKStepOne.setOnClickListener { _ -&amp;gt;
        stepDone(R.id.fragmentStepOne)
    }
}

}

Step 2 Write your own flow
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 2
1. Write your own flow step 2. Write your own flow
Next