cancel
Showing results for 
Search instead for 
Did you mean: 

Flow crashes when using different Android theme than FioriTheme.Onboarding

0 Kudos

Hi SDK-professionals!

We are migration our app from SMP SDK to Android BTP SDK 4.0.5. Our existing app has a customized theme, based on Theme.MaterialComponents.Light.DarkActionBar.Bridge. To isolate the issue, we use a SAP-Wizard generated demo app.

When using com.sap.cloud.mobile.flowv2.core.Flow for onboarding, an exception is thrown:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company
.chsbtpsdkdemo5b/com.sap.cloud.mobile.flowv2.core.FlowActivity}: java.lang.IllegalStateException:
This Activity already has an action bar supplied by the window decor. Do not request
Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar
instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3846)

The exception will be thrown, independent of using FlowOptions.appTheme=OnboardingTheme_NoActionBar or FlowOptions.appTheme=OnboardingTheme.

Otherwise, there is no issue, when changing the app's theme to FioriTheme.Onboarding.

AndroidManifest.xml
<application
android:name=".app.SAPWizardApplication"
...
android:theme="@style/MyAppTheme">
styles.xml
<style name="MyAppTheme" parent="Theme.MaterialComponents.DayNight">
</style>
<style name="MyAppTheme.NoActionBar" parent="MyAppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
</style>
<style name="OnboardingTheme" parent="FioriTheme.Onboarding">
<!-- Customize your theme here. -->
</style>
<style name="OnboardingTheme.NoActionBar" parent="OnboardingTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
</style>
WelcomeActivity.java
FlowContext flowContext = new FlowContextBuilder()
.setApplication(appConfig)
.setMultipleUserMode(false)
.setFlowStateListener(new WizardFlowStateListener(
(SAPWizardApplication) context.getApplication()))
.setFlowOptions(new FlowOptions() {
@Override
public int getApplicationTheme() {
return R.style.OnboardingTheme_NoActionBar; or
// return R.style.OnboardingTheme; }
})
.build();
Flow.start(context, flowContext, (requestCode, resultCode, data) -> {
...
});

How can be run the onboarding flow while using an app theme based on Theme.MaterialComponents.Light.DarkActionBar.Bridge?

Accepted Solutions (1)

Accepted Solutions (1)

flyingfish
Explorer

For the theme set in application level in AndroidManifest.xml, it should be a `NoActionBar` theme so that it would be successful to start FlowActivity. Or add the following two lines into the theme:

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

If the application is using some Fiori components, it's highly recommended for the theme to extend `Theme.Fiori.Horizon`. Otherwise, some Fiori attributes may be required to define in the customized theme by yourselves.

As for the application theme in FlowOptions, it has to extend a Fiori based theme and we strongly recommend to extend `FioriTheme.Onboarding` to make sure Flows works properly. The onboarding screens in Flows exactly follow the Fiori design, so a Fiori based theme that covers Fiori attributes used in Flows is necessary.

So in this case, you can add those two lines into `MyAppTheme` or just use `MyAppTheme.NoActionBar` for SAPWizardApplication in AndroidManifest.xml.

0 Kudos

Hello Bruce,

thanks for your reply. I spent a lot of time, finding the easiest solution. Just adding the two window* items was my first attempt, but didn't work for my apps. I don't know why, maybe because of using material bridge styles or something else. In the end, the cheapest solution was extending the application's theme from FioriTheme.Onboarding.

This change corrupted all existing activities of course. To make them refloat again, I set the original application's theme as style to every single activity's item in the manifest files:

<activity
android:name=".AppInfoActivity" android:theme="@style/Mdg"
....
/>

This was easy to do and works fine. But there has been left a bitter taste. Just for adding SAP connection functionality, the application's theme must be changed is really quirky.

flyingfish
Explorer
0 Kudos

Hello Christian,

Well, I'm not sure why the solution doesn't work for your apps. I just tested with a SAP-Wizard (Android BTP SDK 4.0.5.) generated demo app, it works though application theme using material bridge. If you want, I can attach the demo app.

WelcomeActivity.java
FlowContext flowContext = new FlowContextBuilder()
        .setApplication(appConfig)
        .setMultipleUserMode(false)
        .setFlowStateListener(new WizardFlowStateListener(
               (SAPWizardApplication) context.getApplication()))
        .setFlowOptions(new FlowOptions() {
            @Override<
            public boolean isDeleteRegistrationConfirmationNeeded() {
                return false;
            }
            @Override
            public int getApplicationTheme() {
                return R.style.OnboardingTheme_NoActionBar;
            }
        })
        .build();
AndroidManifest.xml
<application
    android:name=".app.SAPWizardApplication"
        ...
    android:theme="@style/MyAppTheme">
styles.xml
<style name="MyAppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
<style name="MyAppTheme.NoActionBar" parent="MyAppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionModeOverlay">true</item>
</style>
<style name="OnboardingTheme" parent="FioriTheme.Onboarding">
    <!-- Customize your theme here. -->
</style>
<style name="OnboardingTheme.NoActionBar" parent="OnboardingTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionModeOverlay">true</item>
</style>

Answers (0)