MVVM-Architecture | The practice of MVVM + Jetpack architecture in Android | Model View Controller library
kandi X-RAY | MVVM-Architecture Summary
kandi X-RAY | MVVM-Architecture Summary
The practice of MVVM + Jetpack architecture in Android.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of MVVM-Architecture
MVVM-Architecture Key Features
MVVM-Architecture Examples and Code Snippets
Community Discussions
Trending Discussions on MVVM-Architecture
QUESTION
I have a single activity Kotlin-based app that starts a foreground service with:
...ANSWER
Answered 2022-Feb-17 at 08:53When you call "this" you are refering the actual class; in this case 'MyRepository'. This class is not binded to any Android context so is not a valid parameter for your intent. You will need to inject the application context through the constructor.
Anyways, as far as MVVM is concerned, it does not say where a service should be started. Only depends on the function to be performed by the service. For example, a music service should not be started from a repository because repositories are supposed to connect to the data layer.
QUESTION
I'm following this tutorial on using MVVM with Retrofit
https://medium.com/@ronkan26/viewmodel-using-retrofit-mvvm-architecture-f759a0291b49
where the user places MutableLiveData inside the Repository class:
...ANSWER
Answered 2021-Mar-23 at 18:00The solution you're looking for depends on how your app is designed. There are several things you can try out:
- Keep your app modularized - as @ADM mentioned split your repository into smaller
- Move live data out of repository - it is unnecessary to keep live data in a repository (in your case singleton) for the entire app lifecycle while there might be only few screens that need different data.
- That's being said - keep your live data in view models - this is the most standard way of doing. You can take a look at this article that explains Retrofit-ViewModel-LiveData repository pattern
- If you end up with complicated screen and many live data objects you can still map entities into screen data representation with events / states /commands (call it as you want) which are pretty well described here. This way you have single
LiveData
and you just have to map your entities.
Additionaly you could use coroutines with retrofit as coroutines are recomended way now for handling background operations and have Kotlin support if you wanted to give it a try.
Also these links might halpe you when exploring different architectures or solutions for handling your problem architecture-components-samples or architecture-samples (mostly using kotlin though).
QUESTION
In MVVM we have Activities and Fragments. Fragments and Activities have access to ViewModel. ViewModles have access to Repository. Repository has access to local and online database.
I want to build a Service component so that when the application is put on background the Service should continue to write to the local database.
This is how my application looks like:
https://source.coderefinery.org/Karagoez/mytourassistent
I couldn't find reliable information on how Service are implemented in MVVM architecture.
Should the Service get the viewModel of the Activity it's called from and call repository from that?
Should the Service be defined inside repository?
How should the Service component be implemented in the MVVM architecture when the Service is writing to database?
A similar question is asked there: What is the right place to start a service in MVVM architecture Android
But it get two answers that are quite different from each other.
...ANSWER
Answered 2021-May-21 at 14:17You can use LifecycleService
and use it like you do it in Activity or Fragment:
QUESTION
I am working on a SwiftUI project, where I use the MVVM-architecture.
When changing a View-model object property from the SwiftUI view, it causes a memory conflict crash in the view-model object.
The error is of the type: Simultaneous accesses to 0x600003591b48, but modification requires exclusive access.
In steps, here is what happens:
- View-model property is changed from view
- View-model property changes model property
- Model property notifies about changes
- View-model receives change notification
- View-model access model object
- Crash occur due to memory conflict
Relevant code snippets are seen below. Xcode project is a standard SwiftUI project.
The error will happen, after first clicking the add button, and then the modify button.
If the "update" code is moved into the "receiveValue" closure, the error will not occur. Likewise, the error will not occur, if the View-model class is made non-generic.
To my best knowledge, the code is all-right, so I suspect it is a compiler problem. But I am not sure.
...ANSWER
Answered 2021-Apr-23 at 16:52Short version: require AnyObject
for ModelType
.
Long version:
You're trying to read from self.model
while you're in the middle of setting self.model
. When you say "If the "update" code is moved into the "receiveValue" closure, the error will not occur," this isn't quite correct. I expect what you mean is you wrote this:
QUESTION
I have a tableView with several cells (created by MVVM-architecture).
In ViewController I fill my tableView like this:
...ANSWER
Answered 2021-Jan-28 at 13:20In Tableview each row you can load UITableViewCell with pass collectionviewdata
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install MVVM-Architecture
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page