SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Restore, Reset and Logout Applications Using the Flows Component

Learn how to use the SAP BTP SDK for Android Flows component to handle application restore, passcode timeout, reset and logout scenarios.

Overview

🎓 beginner 30 min. SAP BTP Sdk For AndroidBeginnerAndroidMobileSAP Business Technology Platform

You will learn

  • โœ”How to handle application restore and passcode timeouts using the Flows component
  • โœ”How to reset an application using the Flows component
  • โœ”How to logout of an application using the Flows component [ACCORDION-BEGIN [Step 1: ](Application restore)] After onboarding, the next time users open the mobile app, the restore flow will be started. Basically, the restore flow consists of the screen unlocking the app with either the passcode or biometric information, if enabled. The restore flow will also check whether the passcode is expired based on the setting defined in the passcode policy. If the passcode is expired, the restore flow will ask the user to create a new passcode and launch a “change passcode” flow. Similar to the onboarding flow, the restore flow will also listen to the flow states and notify corresponding events to the client code. The flows component will automatically determine whether to use the onboarding or restore flow, so the app can use the same client code for both flows. [OPTION BEGIN [Kotlin]] 1. Open the project you previously created using the SAP BTP SDK Wizard for Android. 2. In Android Studio, on Windows, press Ctrl+N, or, on a Mac, press command+O, and type WelcomeActivity to open WelcomeActivity.kt. 3. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type startOnboarding to move to the startOnboarding method. As we mentioned in Get Familiar with the Flows Component by a Wizard Generated Application, this method starts an onboarding flow. After onboarding, the next time the app starts, the same method is called and the Flows component detects that the user is already onboarded and starts the restore flow. The client code does not need handle the logic to explicitly start a restore flow. !
    Flow restore starting method
    Flow restore starting method
    4. The restore flow will notify the same events as the onboarding flow and one additional UnlockWithPasscode event, which is specific to the restore flow. When the app is unlocked using a passcode, the client code can get the passcode from the onUnlockWithPasscode callback of the FlowStateListener instance and open the secure store. Customize the Onboarding Flow explains the events notified in the onboarding flow. 5. When the app is put to background, the Flows component will monitor whether the passcode is timed out based on the “Lock Timeout” value defined in the passcode policy. When the passcode is timed out and the app is put to foreground again, a timeout unlock flow will be started. This is the FlowType.TIMEOUT_UNLOCK flow type, which is used internally by the Flows component for the passcode timeout scenario. This flow’s function is exactly the same as that of the restore flow. [OPTION END] [OPTION BEGIN [Java]] 1. Open the project you previously created using the SAP BTP SDK Wizard for Android. 2. In Android Studio, on Windows, press Ctrl+N, or, on a Mac, press command+O, and type WelcomeActivity to open WelcomeActivity.java. 3. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type startFlow to move to the startFlow method. As we mentioned in Get Familiar with the Flows Component by a Wizard Generated Application, this method starts an onboarding flow. After onboarding, the next time the app starts, the same method is called and the Flows component detects that the user is already onboarded and starts the restore flow. The client code does not need handle the logic to explicitly start a restore flow. !
    Flow restore starting method
    Flow restore starting method
    4. The restore flow will notify the same events as the onboarding flow and one additional UnlockWithPasscode event, which is specific to the restore flow. When the app is unlocked using a passcode, the client code can get the passcode from the onUnlockWithPasscode callback of the FlowStateListener instance and open the secure store. Customize the Onboarding Flow explains the events notified in the onboarding flow. 5. When the app is put to background, the Flows component will monitor whether the passcode is timed out based on the “Lock Timeout” value defined in the passcode policy. When the passcode is timed out and the app is put to foreground again, a timeout unlock flow will be started. This is the FlowType.TIMEOUT_UNLOCK flow type, which is used internally by the Flows component for the passcode timeout scenario. This flow’s function is exactly the same as that of the restore flow. [OPTION END] [VALIDATE_1] [ACCORDION-END] [ACCORDION-BEGIN [Step 2: ](Reset an application)] There may be occasions when the user wants to reset the app to initial state. The reset flow is designed to clear all the application data, user data, and security data managed by the Flows component. [OPTION BEGIN [Kotlin]] 1. Open the project you previously created using the SAP BTP SDK Wizard for Android. 2. In Android Studio, on Windows, press Ctrl+N, or, on a Mac, press command+O, and type SettingsFragment to open SettingsFragment.kt. 3. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type startResetFlow to move to the startResetFlow method. To start the flow to reset application, set the flow type to FlowType.RESET for the FlowContext instance, and then start the flow with this FlowContext instance. The entire process to reset the application will be handled automatically. !
    App reset flow
    App reset flow
    4. When the reset flow is started, the default behavior is for a dialog to be displayed, asking the user for confirmation. !
    App reset dialog
    App reset dialog
    You can customize your client code so that the reset flow hides this dialog by setting the value of needConfirmWhenReset parameter to false for the FlowOptions instance and set this FlowOptions instance for the FlowContext instance to start the reset flow. Kotlin val flowContext = FlowContextBuilder() .setFlowType(FlowType.RESET) .setFlowOptions(FlowOptions( needConfirmWhenReset = false )) .build() Flow.start(this, flowContext) 5. Before removing all the data managed by the Flows component, the reset flow will notify the ApplicationReset event. You can use the onApplicationReset callback of the FlowStateListener instance to insert its own logic for application reset, for example to clear the data managed by the client code and un-register the push token. In Android Studio, on Windows, press Ctrl+N, or, on a Mac, press command+O, and type WizardFlowStateListener to open WizardFlowStateListener.kt. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type onApplicationReset to move to the onApplicationReset method. !
    App reset listener
    App reset listener
    [OPTION END] [OPTION BEGIN [Java]] 1. Open the project you previously created using the SAP BTP SDK Wizard for Android. 2. In Android Studio, on Windows, press Ctrl+N, or, on a Mac, press command+O, and type SettingsFragment to open SettingsFragment.java. 3. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type onCreatePreferences to move to the onCreatePreferences method. To start the flow to reset the application, set the flow type to FlowType.RESET for the FlowContext instance, and then start the flow with this FlowContext instance. The entire process to reset application will be handled automatically. !
    App reset flow
    App reset flow
    4. When the reset flow is started, the default behavior, is for a dialog to be displayed, asking the user for confirmation. !
    App reset dialog
    App reset dialog
    You can customize your client code so that the reset flow hides this dialog by overriding the isResetConfirmationNeeded function of the FlowOptions instance to return false and set this FlowOptions instance for the FlowContext instance to start the reset flow. Java FlowContext flowContext = new FlowContextBuilder() .setFlowType(FlowType.RESET) .setFlowOptions(new FlowOptions(){ @Override public boolean isResetConfirmationNeeded() { return false; } }).build(); Flow.start(this, flowContext); 5. Before removing all the data managed by the Flows component, the reset flow will notify the ApplicationReset event. You can use the onApplicationReset callback of the FlowStateListener instance to insert its own logic for application reset, for example to clear the data managed by the client code and un-register the push token. In Android Studio, on Windows, press Ctrl+N, or, on a Mac, press command+O, and type WizardFlowStateListener to open WizardFlowStateListener.java. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type onApplicationReset to move to the onApplicationReset method. !
    App reset listener
    App reset listener
    [OPTION END] [VALIDATE_2] [ACCORDION-END] [ACCORDION-BEGIN [Step 3: ](Application logout)] The logout flow will try to logout the current user if network is available, then remove the OAuth2 token of the current user if the app is authenticated with OAuth2. No matter the network is available or not, after the flow, the user needs to be authenticated again when making an API call to the server. 1. Open the project you previously created using the SAP BTP SDK Wizard for Android. 2. In Android Studio, on Windows, press Ctrl+N, or, on a Mac, press command+O, and type EntitySetListActivity to open EntitySetListActivity.kt. 3. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type onOptionsItemSelected to move to the onOptionsItemSelected method. To start the flow to logout of the application, set the flow type to FlowType.LOGOUT for the FlowContext instance, and then start the flow with this FlowContext instance. !
    Flow logout starting method
    Flow logout starting method
    4. When the logout flow is started, the default behavior is for a dialog to be displayed, asking the user for confirmation. !
    App logout dialog
    App logout dialog
    You can customize your client code so that the logout flow hides this dialog by setting the value of needConfirmWhenLogout parameter to false for the FlowOptions instance and set this FlowOptions instance for the FlowContext instance to start the reset flow. Kotlin val flowContext = FlowContextBuilder() .setFlowType(FlowType.LOGOUT) .setFlowOptions(FlowOptions( needConfirmWhenLogout = false )) .build() Flow.start(this, flowContext) 5. Logout flow will not automatically remove the push registration. Client code can implement the callback function FlowActivityResultCallback to delete the Firebase push token if it does not want to receive push notifications after logout. The logout flow will trigger the callback function after a successful logout. Kotlin Flow.start( this, FlowContextRegistry.flowContext. copy( flowType = FlowType.LOGOUT)){ _, resultCode, _-> if(resultCode ==RESULT_OK) { SDKInitializer.getService (FirebasePushService::class)?.also { FirebaseMessaging.getInstance(). deleteToken().addOnSuccessListener { Log.e("PushService","PushService token was revoked!") } .addOnFailureListener { e1: Exception? -> Log.e("PushService","PushService token couldn't be revoked!:$e1") } } } } Congratulations! You now have learned how to restore, reset and logout an application using the Flows component! [VALIDATE_3] [ACCORDION-END]
Haoyue Feng H Haoyue Feng April 26, 2024
Created by March 27, 2024
Contributors

Prerequisites

Prerequisites

Steps

Details

You will learn

  • How to handle application restore and passcode timeouts using the Flows component
  • How to reset an application using the Flows component
  • How to logout of an application using the Flows component

Step 1 Application restore
โ€”

After onboarding, the next time users open the mobile app, the restore flow will be started. Basically, the restore flow consists of the screen unlocking the app with either the passcode or biometric information, if enabled. The restore flow will also check whether the passcode is expired based on the setting defined in the passcode policy. If the passcode is expired, the restore flow will ask the user to create a new passcode and launch a “change passcode” flow.

Similar to the onboarding flow, the restore flow will also listen to the flow states and notify corresponding events to the client code.

The flows component will automatically determine whether to use the onboarding or restore flow, so the app can use the same client code for both flows.

  1. Open the project you previously created using the SAP BTP SDK Wizard for Android.

  2. In Android Studio, on Windows, press Ctrl+N, or, on a Mac, press command+O, and type WelcomeActivity to open WelcomeActivity.kt.

  3. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type startOnboarding to move to the startOnboarding method. As we mentioned in Get Familiar with the Flows Component by a Wizard Generated Application, this method starts an onboarding flow. After onboarding, the next time the app starts, the same method is called and the Flows component detects that the user is already onboarded and starts the restore flow. The client code does not need handle the logic to explicitly start a restore flow.

    !

    Flow restore starting method
    Flow restore starting method

  4. The restore flow will notify the same events as the onboarding flow and one additional UnlockWithPasscode event, which is specific to the restore flow. When the app is unlocked using a passcode, the client code can get the passcode from the onUnlockWithPasscode callback of the FlowStateListener instance and open the secure store. Customize the Onboarding Flow explains the events notified in the onboarding flow.

  5. When the app is put to background, the Flows component will monitor whether the passcode is timed out based on the “Lock Timeout” value defined in the passcode policy. When the passcode is timed out and the app is put to foreground again, a timeout unlock flow will be started. This is the FlowType.TIMEOUT_UNLOCK flow type, which is used internally by the Flows component for the passcode timeout scenario. This flow’s function is exactly the same as that of the restore flow.

Step 2 Reset an application
+
Step 3 Application logout
+

Resources

Discussion

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

Submit detailed feedback Discuss in Community
Steps
Step 1 of 3
1. Application restore 2. Reset an application 3. Application logout

Learn more →