Skip to content

Commit

Permalink
Merge pull request #11 from FengHaoyue/main
Browse files Browse the repository at this point in the history
Update based on 24.0.4 release
  • Loading branch information
FengHaoyue authored Apr 15, 2024
2 parents a23bcee + 46960ed commit 38b114e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 27 deletions.
Binary file modified tutorials/sdk-android-flows-passcode/forget-passcode-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tutorials/sdk-android-flows-passcode/verify-passcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tutorials/sdk-android-flows-restore/flow-restore-kotlin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tutorials/sdk-android-flows-restore/reset-app-kotlin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
author_name: Haoyue Feng
author_profile: https://github.com/Fenghaoyue
title: Restore and Reset Applications Using the Flows Component
description: Learn how to use the SAP BTP SDK for Android Flows component to handle application restore, passcode timeout, and reset scenarios.
title: Restore, Reset and Logout Applications Using the Flows Component
description: Learn how to use the SAP BTP SDK for Android Flows component to handle application restore, passcode timeout, reset and logout scenarios.
auto_validation: true
time: 30
tags: [ tutorial>beginner, operating-system>android, topic>mobile, products>sap-business-technology-platform]
Expand All @@ -20,6 +20,7 @@ primary_tag: products>sap-btp-sdk-for-android
### 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 an application using the Flows component

---

Expand All @@ -31,31 +32,32 @@ Similar to the onboarding flow, the restore flow will also listen to the flow st

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 [Java]]

[OPTION BEGIN [Kotlin]]

1. Open the project you [previously created](sdk-android-wizard-app) 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`.
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 **`startFlow`** to move to the `startFlow` method. As we mentioned in [Get Familiar with the Flows Component by a Wizard Generated Application](sdk-android-flows-wizard), 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.
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](sdk-android-flows-wizard), 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-java.png)
!![Flow restore starting method](flow-restore-kotlin.png)

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](sdk-android-flows-onboarding) 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 [Kotlin]]
[OPTION BEGIN [Java]]

1. Open the project you [previously created](sdk-android-wizard-app) 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`.
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](sdk-android-flows-wizard), 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-kotlin.png)
!![Flow restore starting method](flow-restore-java.png)

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](sdk-android-flows-onboarding) explains the events notified in the onboarding flow.

Expand All @@ -70,6 +72,41 @@ The flows component will automatically determine whether to use the onboarding o

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](sdk-android-wizard-app) 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](reset-app-kotlin.png)

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](reset-app-dialog.png)

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](reset-listener-kotlin.png)

[OPTION END]

[OPTION BEGIN [Java]]

1. Open the project you [previously created](sdk-android-wizard-app) using the SAP BTP SDK Wizard for Android.
Expand Down Expand Up @@ -106,43 +143,68 @@ There may be occasions when the user wants to reset the app to initial state. Th

[OPTION END]

[OPTION BEGIN [Kotlin]]
[VALIDATE_2]
[ACCORDION-END]

[ACCORDION-BEGIN [Step 3: ](Application logout)]

The logout flow will try to logout the current user if the network is available, then remove the OAuth2 token of the current user if the app is authenticated with OAuth2. No matter whether 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](sdk-android-wizard-app) 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`.
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 **`onCreatePreferences`** to move to the `onCreatePreferences` 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 application will be handled automatically.
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.

!![App reset flow](reset-app-kotlin.png)
!![Flow logout starting method](flow-logout-kotlin.png)

4. When the reset flow is started, the default behavior is for a dialog to be displayed, asking the user for confirmation.
4. When the logout flow is started, the default behavior is for a dialog to be displayed, asking the user for confirmation.

!![App reset dialog](reset-app-dialog.png)
!![App logout dialog](logout-app-dialog.png)

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.
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.RESET)
.setFlowType(FlowType.LOGOUT)
.setFlowOptions(FlowOptions(
needConfirmWhenReset = false
needConfirmWhenLogout = 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.
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.

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](reset-listener-kotlin.png)
```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? ->

[OPTION END]
Log.e("PushService","PushService token couldn't be revoked!:$e1")
}
}
}
}
```

Congratulations! You now have learned how to restore and reset application using the Flows component!
Congratulations! You now have learned how to restore, reset and logout an application using the Flows component!

[VALIDATE_2]
[VALIDATE_3]
[ACCORDION-END]

---
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ Client code may use its own screens in onboarding process or implement customize

>Please see [Flows Theme and Style](https://help.sap.com/doc/f53c64b93e5140918d676b927a3cd65b/Cloud/en-US/docs-en/guides/features/onboarding/android/newflows/FlowStyles.html) for more information on UI customization.

Congratulations! You now have learned how to customize the styles and themes for the UI screens of Flows component!
>For Android API Level 30 or above, we recommend that you use the theme download feature, which will apply the theme to the client application. Please see [How to Use an Application Theme From a Client Application](https://help.sap.com/doc/f53c64b93e5140918d676b927a3cd65b/Cloud/en-US/docs-en/guides/features/application-themes/android/use-theme-from-client-app.html) for the theme download feature.

Congratulations! You now have learned how to customize the styles and themes of the UI screens of Flows component!

[VALIDATE_1]
[ACCORDION-END]
Expand Down
Binary file modified tutorials/sdk-android-flows-wizard/flow-starting-kotlin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The [Flows](https://help.sap.com/doc/f53c64b93e5140918d676b927a3cd65b/Cloud/en-U

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 **`startFlow`** to move to the `startFlow` method. To start the onboarding process, firstly create a **`FlowContext`** instance that contains the information required by the flow, such as the application information, the status of multi-user mode, the flow state listener, etc. Then call the `start` method of the `Flow` class to start the onboarding flow, allowing the entire onboarding process to be handled automatically.
3. On Windows, press **`Ctrl+F12`**, or, on a Mac, press **`command+F12`**, and type **`startFlow`** to move to the `startOnboarding` method. To start the onboarding process, firstly create a **`FlowContext`** instance that contains the information required by the flow, such as the application information, the status of multi-user mode, the flow state listener, etc. Then call the `start` method of the `Flow` class to start the onboarding flow, allowing the entire onboarding process to be handled automatically.

!![Flow starting method](flow-starting-kotlin.png)

Expand Down

0 comments on commit 38b114e

Please sign in to comment.