Giter VIP home page Giter VIP logo

Comments (11)

Zhuinden avatar Zhuinden commented on June 16, 2024

Hello,

MediaViewModel would exist if it is bound as a service by a key in the history. When is MediaViewModel accessed in such a way that your view cannot find it, as the OutdatedScreen overwrites this attempt to get it?

If you are using Fragments, I tend to use private val viewModel by lazy { lookup<MediaViewModel>() } and access it in onViewCreated to ensure its initialization.

from simple-stack.

MikaReesu avatar MikaReesu commented on June 16, 2024

private val viewModel by lazy { lookup< MediaViewModel >() }

I am also using it in all my fragments.

When it is detected that the app is too old. I set the history to OutdatedScreen and I forward user there.

backstack.setHistory( History.of(OutdatedScreen()), StateChange.FORWARD )

What is weird is that, once app is updated, the app is relaunch I guess, and the splashscreen is triggered which will set the history to the MainScreen. So "normally" OutdatedScreen shouldn't be in the history or at least set as the history.

from simple-stack.

Zhuinden avatar Zhuinden commented on June 16, 2024

backstack.setHistory( History.of(OutdatedScreen()), StateChange.FORWARD )

What is weird is that, once app is updated, the app is relaunch I guess, and the splashscreen is triggered which will set the history to the MainScreen. So "normally" OutdatedScreen shouldn't be in the history or at least set as the history.

It sounds like people get redirected from your MediaScreen to OutdatedScreen, but MediaFragment accessed the model when "it is no longer there" as a result of redirection. Without the relevant source code, I could guess something like accessing the model in onDestroy without having been in onCreateView, or as part of an asynchronous operation that finishes only after Fragment is destroyed but async op is not cancelled.

Something like

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    val model = model
    ...
}

Can help sometimes. Otherwise, I'd look for what happens when your app restores to MediaFragment after process death.

from simple-stack.

MikaReesu avatar MikaReesu commented on June 16, 2024

I don't think that way. The redirection towards the OutdatedScreen is not implemented in that view.

The setHistory(OutdatedScreen) happened in the MainScreen.

So, you think that when there was the redirection towards MediaScreen, the MediaModel was no longer there?

from simple-stack.

Zhuinden avatar Zhuinden commented on June 16, 2024

I think what happens is that the MediaFragment is recreated after process death and somehow "later than onViewCreated" attempts to access that VM even though the history is already reset to OutdatedScreen.

from simple-stack.

MikaReesu avatar MikaReesu commented on June 16, 2024

Seems strange, any idea how to avoid the crash?

from simple-stack.

Zhuinden avatar Zhuinden commented on June 16, 2024

It depends on your code, which I don't see. There should theoretically be no such timing based problems since... a long time ago (2.1.0). The bug itself is not in simple-stack, so there is nothing I can fix. If you don't really know why MediaFragment exists despite the keys being reset, make sure your key classes are data class or override getFragmentTag() (they are getClassName() by default, but I usually use data class toString to support different tags based on parameters).

The hackiest "fix attempt bandaid" can be putting your setHistory call in handler.post {} but it should not be necessary.

from simple-stack.

MikaReesu avatar MikaReesu commented on June 16, 2024

I see, thank you.

from simple-stack.

Zhuinden avatar Zhuinden commented on June 16, 2024

Notify back if you figured out why your scope is missing.

from simple-stack.

Zhuinden avatar Zhuinden commented on June 16, 2024

Hello, have you figured it out? I totally forgot this was open. @MikaReesu

from simple-stack.

Zhuinden avatar Zhuinden commented on June 16, 2024

I will assume this was fixed.

from simple-stack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.