Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dynamic feature] Crash when navigate back to fragment #39

Closed
georgious1 opened this issue Dec 25, 2019 · 11 comments
Closed

[Dynamic feature] Crash when navigate back to fragment #39

georgious1 opened this issue Dec 25, 2019 · 11 comments
Assignees

Comments

@georgious1
Copy link

I am using fragment in dynamic feature module.
In fragment have these lines of code:
override fun onAttach(context: Context?) { super.onAttach(context) SplitCompat.install(context) }

Everything works fine. But when i am trying to navigate back to this fragment i am getting ResourceNotFoundException. It looks like my dynamic module wasnt even initialized.

Issue was solved using next lines
override fun onResume() { super.onResume() SplitCompat.install(context) }

What is the proper way to fix it ?

@keyboardsurfer
Copy link
Member

Thanks for reporting this. It seems like this is not an issue with the sample itself but one you're encountering in your own application.

Can you please give me some more information on your Activity / Fragment / Module setup & stacktrace over at StackOverflow and link it here?

@keyboardsurfer
Copy link
Member

We need your input to act on this issue.
This issue will be closed soon unless there is further actionable input.

@Rishabh-sx
Copy link

Rishabh-sx commented May 5, 2020

Hi @keyboardsurfer @georgious1 , I am also facing this when navigating back to fragment.

I have added this in activity.
override fun onResume() { super.onResume() SplitCompat.install(context) }

But I am getting crash in API response.

@Rishabh-sx
Copy link

Any Standard way to fix this ?

@keyboardsurfer
Copy link
Member

Is there a way for you to reproduce the issue within this sample or a clone of it?

@Rishabh-sx
Copy link

Hi @keyboardsurfer, Not in this sample but in our application we are facing this after following all the steps to turn on Dynamic Delivery.

@keyboardsurfer
Copy link
Member

I understand this. What I'm asking you is to try and reproduce the issue on the sample at hand. If it's reproducible here we can take a closer look.

@Rishabh-sx
Copy link

Okay, let me check and get back to you.

@georgious1
Copy link
Author

georgious1 commented May 15, 2020

@Rishabh-sx i added workaround to fix this issue.
enable SplitCompat to have immediate access for code and resources
https://developer.android.com/guide/playcore/dynamic-delivery#activity_splitcompat

Android docs says :
"As long as you enable SplitCompat for your base application context and the activities in your dynamic feature module, after a request for an on demand module reports as INSTALLED, you can start using its code and resources as if it were a part of the base APK..."

BUT

  1. I enabled SplitCompat in my Application class, and my dynamic feature modules didnt have any activities, only fragments. But for sure i added following code to my activity(which was not part of DFModule).
override fun attachBaseContext(baseContext: Context) {
        super.attachBaseContext(baseContext)
        SplitCompat.installActivity(baseContext)
    }

AND
2) When receive SplitInstallSessionStatus.INSTALLED status i immediately called
SplitCompat.install(context.applicationContext) with application context. And only after that i was able to use any code from DFModule

  1. Added following to Fragment from DFModule
override fun onAttach(context: Context?) {
        super.onAttach(context)
        SplitCompat.install(context)

Actually i think just number (2) did all the trick, and enabling SplitCompat in fragments looks like redundant, but wont create any issues.

@georgious1
Copy link
Author

georgious1 commented May 15, 2020

Ah, and small update here, rechecked docs. Maybe its new addition, but it describes step (2) from example above :
".. If you want to access assets or resources that exist in the newly installed module from a different installed module of your app, you must do so using the application context. The context of the component that's trying to access the resources will not yet be updated. Alternatively, you can recreate that component or install SplitCompat upon it after the dynamic feature module install. "

So having next code should be enough :

SplitInstallStateUpdatedListener { state ->
       when (state.status()) {
           SplitInstallSessionStatus.INSTALLED -> {
               SplitCompat.install(context.applicationContext)

               // CAN USE CODE FROM DFModule
           }
       }
   }

@Rishabh-sx
Copy link

Hi @georgious1 , Thanks for sharing this information. Let me share this with my team and ask them to check if we are missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants