Comments (11)
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.
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.
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.
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.
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.
Seems strange, any idea how to avoid the crash?
from simple-stack.
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.
I see, thank you.
from simple-stack.
Notify back if you figured out why your scope is missing.
from simple-stack.
Hello, have you figured it out? I totally forgot this was open. @MikaReesu
from simple-stack.
I will assume this was fixed.
from simple-stack.
Related Issues (20)
- Can I Use @styles/Theme.MyComposeTheme on AndroidManifests.xml? HOT 3
- Question: What is the purpose of RegistrationViewModel inside ServiceProvider in extension-compose-example? HOT 4
- What is the proper way to add a key to the top even if it already exists in the backstack? HOT 2
- Publish to MavenCentral instead of just Jitpack.io
- Unable to start activity ComponentInfo{com.xxxxxxxxxx.yyyyyy/com.xxxxxxxxxx.yyyyyy.activities.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment q2.v1: could not find Fragment constructor HOT 7
- How to 'lookup<>()' scoped class from an Android Service HOT 2
- Lazy initialization of ScopedServices HOT 2
- KMM support? HOT 2
- Screen can get the service from wrong scope during back animation HOT 6
- Backstack is not available in a child Fragment's onCreate after process death
- DialogFragment and BottomDialogFragment as part of navigation stack, question HOT 2
- Verify that the new `setParentServices()`'s `lookupFromScope(..., EXPLICIT)` behavior is what is expected
- Updating the Compose example to Compose 1.5.0 requires AGP 8.1
- Should Simple Stack be used in new projects HOT 14
- Crash due to activity.onBackPressed() when removing fragment hosting a WebView in AndroidView {} + FADE HOT 15
- Backstack with espresso HOT 3
- Up navigation examples are hard to find HOT 3
- Consider adding Backstack.services() method as in GlobalServices.services() HOT 4
- Extensions should support Fragment in-app predictive back animations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-stack.