Skip to Content

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.
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
FengHaoyueHaoyue FengApril 26, 2024
Created by
sandeep-tds
January 9, 2023
Contributors
sandeep-tds
FengHaoyue

Prerequisites

  • Step 1

    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.

    Which of the following statements are correct?

  • Step 2

    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.

    Which of the following statements are correct?

  • Step 3

    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
    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

      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
      Copy
      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
      Copy
      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!

    Which of the following statements are correct?

Back to top