简体   繁体   中英

Dynamic Feature Crashing Resource not found on Application Relaunch

My app works fine after downloading Dynamic Feature onDemand Module but as soon as I restart my app the app crashes with Exception. Heres the code that I copied from google dynamic features [sample repo][1]

private fun onSuccessfulLoad(moduleName: String, launch: Boolean) {
    if (launch) {
        when (moduleName) {
            pagesfeatures -> launchActivity(mainActivity)
          
        }
    }

}

I have already overridden the code in BaseActivity and App class

open class BaseActivity: AppCompatActivity() {
    override fun attachBaseContext(newBase: Context?) {
        super.attachBaseContext(newBase)
        SplitCompat.install(this)
    }
}
 public class App extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        SplitCompat.install(base);
    }
}

But its crashing when I revisit the application

The Exception thats occurring in my logs Crashlytics

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.qp.readquranoffline.holybookreading/com.mycode.pagesfeature.activities.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7e010000
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3621)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2190)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:268)
at android.app.ActivityThread.main(ActivityThread.java:8004)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:627)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)

Caused by android.content.res.Resources$NotFoundException: Resource ID #0x7e010000
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:248)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2400)
at android.content.res.Resources.getAnimation(Resources.java:1277)
at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:138)
at com.mycode.quranpagesfeature.activities.MainActivity.onCreate(MainActivity.kt:158)
at android.app.Activity.performCreate(Activity.java:8058)
at android.app.Activity.performCreate(Activity.java:8042)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1315)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3594)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2190)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:268)
at android.app.ActivityThread.main(ActivityThread.java:8004)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:627)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)


  [1]: https://github.com/googlearchive/android-dynamic-features

In my case, when there's a configuration change it also regenerates the Context in my Activity, and loses the resources that have been injected by SplitCompat . I fix it by loading the resources using ContextCompat .

ContextCompat.getDrawable(context, drawable)

And reinject resource when there`s configuration changes using this in activity

override fun onConfigurationChanged(newConfig: Configuration) {
    SplitCompat.installActivity( baseContext ?: this)
    super.onConfigurationChanged(newConfig)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM