4

I'm currently experimenting with dynamic feature modules and came across a strange problem. I handle configuration changes by implementing the onConfigurationChanged method in my Activity and defining it in the manifest by adding android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|uiMode". This works fine for "normal" apks, however - when I do this in dynamic feature modules I get a Resources$NotFoundException after the device rotated - for resources that have already been resolved correctly before the rotation. So from my point of view I'm missing something to handle correctly for the rotation - I already tried reapplying the SplitCompat.install(<Context>) in the onConfigurationChanged, but this does also not work. Anyone got any idea what I'm doing wrong?

This happens for me with the com.google.android.play:core:1.6.4 library.

2019-11-06 10:33:33.101 5933-5933/? W/ResourceType: No known package when getting value for resource number 0x7e0d00a8
2019-11-06 10:33:33.102 5933-5933/? D/AndroidRuntime: Shutting down VM
2019-11-06 10:33:33.103 5933-5933/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.jumio.dynamicfeature, PID: 5933
android.content.res.Resources$NotFoundException: String resource ID #0x7e0d00a8
        at android.content.res.Resources.getText(Resources.java:339)
        at android.widget.TextView.setText(TextView.java:5496)
Romanski
  • 730
  • 8
  • 27
  • Please try this in your app gradle file: bundle { language { // Specifies that the app bundle should not support // configuration APKs for language resources. These // resources are instead packaged with each base and // dynamic feature APK. enableSplit = false } } – Touhid Dec 10 '19 at 09:29

1 Answers1

4

Finally found the issue that was causing the problem - it seems that the SplitCompat.install(<Context>) needs to be called in onConfigurationChanged - but before super.onConfigurationChanged() is called! This has to be done because super.onConfigurationChanged triggeres the onConfigurationChanged method inside the fragments where I update some parts of the ui.

@Override
public void onConfigurationChanged(Configuration configuration) {
    SplitCompat.install(this);

    super.onConfigurationChanged(configuration);

    ...
}

I also encountered an issue afterwards that Theme attributes could not be resolved after rotation - turns out that if fragments are used, the getTheme method in the activity needs to be adapted as well - themeId is the same id that is also set with setTheme in the onCreate method.

@Override
public Resources.Theme getTheme() {
    Resources.Theme theme = super.getTheme();
    if (themeId != 0) {
        theme.applyStyle(themeId, true);
    }
    return theme;
}
Romanski
  • 730
  • 8
  • 27