771 questions
0
votes
1
answer
47
views
Android ViewModel Methods Fail After First Successful Execution - State Management or Concurrency Issue
In my Android application, I have a UserViewModel that handles various user-related operations (registration, login, username update, password change, etc.). The problem is that after one of these ...
1
vote
2
answers
67
views
Resetting LiveData after consumption in Android ViewModel
I want to modify my Android ViewModel code, which currently uses LiveData, so that the LiveData objects are cleared or reset after they have been consumed by the UI. This is to prevent the UI from re-...
0
votes
0
answers
74
views
How do I set up an Android service in the recommended app architecture
I have inherited a WearOS app, which needs to use the watch sensors to record health data, such as heart rate, temperature and acceleration. The app is made in Java, is around 7 years old and it doesn'...
0
votes
0
answers
36
views
What is the single source of truth in my Fragment with a ViewModel?
I have a Fragment that contains several CheckBoxes:
class TestFragment : Fragment() {
private lateinit var checkBox2er: CheckBox
private lateinit var checkBox3er: CheckBox
// ...
...
4
votes
2
answers
327
views
How to use Dispatchers.IO correctly to read local files on Android?
In the Android documentation it says the following:
Dispatchers.IO - This dispatcher is optimized to perform disk or network I/O outside of the main thread. Examples include using the
Room component, ...
1
vote
1
answer
294
views
How to drag and reorder list in Jetpack Compose?
Can someone help me correct the logic of reordering list. I believe the moveTodo function in viewmodel is not working properly. Reordering is working but not like how it should.
Project Structure
..db
...
2
votes
1
answer
228
views
multiple instances with compose and kotlin
sorry for the English, I'm using a translator.i'm just a beginner, please consider this when replying.i know the code may not be the best. this is just a start.
I'm using the viewmodel to create a ...
0
votes
2
answers
207
views
Optional multi-value filtering function for Room Database Compose/Kotlin
So, I've got a database collection thing I am working on. The main view is just a list of all the stuff in the database, and I'm currently trying to add optional filtering by certain parameters. I ...
0
votes
1
answer
306
views
Android Compose MVVM File Picker Can See File, Cannot Select (Import CSV), permissions, other issues SKD 30+
I've searched everywhere and I can't find any answers that make any sense, and every answer I tried I could find, causes the app to crash instantly. I even got desperate and asked Gemini for help, ...
1
vote
1
answer
157
views
Best way to use ArrayList in in Kotlin/MVVM. StateFlow vs Flow vs suspend
I am trying to upgrade my java code to kotlin but I don't know how to aproach this transition. It seems that I have to perfectly understand corutines which is a pain because it seems too much all at ...
1
vote
2
answers
140
views
Why network call is not triggered while using retrofit with jetpack compose mvvvm
I have an endpoint
https://api.openweathermap.org/data/2.5/weather?q=sukkur,pk&appid=5*****************c
I want to use retrofit to make call to this end point
interface WeatherApiService {
@...
1
vote
2
answers
775
views
How to pass a String parameter to a viewmodel in compose?
How can I pass a String parameter to a ViewModel in Compose? I mean a string variable, not a hardcoded one or an Application stored one. I need to pass it as a parameter. This is just for learning ...
0
votes
2
answers
772
views
Kotlin, cannot create instance of class Viewmodel
I am new to MVVM architecture, I have tried with different options but still getting same exception "cannot able to create an instance ViewModel".
I am using Android Studio Iguana
below is ...
0
votes
1
answer
175
views
Trouble Injecting ViewModel with Hilt in Android Kotlin App
I'm working on an Android app using Kotlin, Jetpack Compose, and Hilt for dependency injection. Despite following the recommended setup for Hilt, I keep encountering a runtime exception when trying to ...
1
vote
0
answers
80
views
Idea needed: How to make viewmodel state - drag&drop in compose list that can be edited
I have a very simple list on the screen. Data goes from viewmodel state from database as observable flow (very ordinary case)
List item is very simple: it has id, name, order_ (the order of item in ...
0
votes
0
answers
66
views
retrieve a single value from room entity using viewmodel
I am trying to implement favoriting feature in my application using room db. I am storing the data from an API call and present it using the ViewModel and MutableLiveData. The problem I going through ...
1
vote
1
answer
903
views
Android Clean Architecture View Model implements callbacks from View
I was just dealing with clean architecture in Android apps and MVVM.
I heard that you shouldn't pass your ViewModel directly to the screen (I use Jetpack Compose) but rather its states and every ...
10
votes
1
answer
2k
views
Android Compose Paging 3 - Loading all pages at once without scrolling in LazyColumn with network call and no inner scrolls
I'm working on an Android Compose project where I'm using Paging 3 along with a LazyColumn to display a list of items fetched from a network call. The default behavior of Paging 3 is to load pages ...
0
votes
1
answer
195
views
Call Multiple ViewModel Functions in a Screen vs Single ViewModel Function
Say in the OrderScreen, we have OrderViewModel(orderRepository) and UserViewModel(userRepository).
Approach #1:
class OrderViewModel(private val orderRepository: OrderRepository) : ViewModel() {
...
0
votes
0
answers
86
views
Andorid Jetpack Compose State not Updating
I am working on a Jet Shopping App using Room DB with reference from HOODLAB youtube video & my full code is build without error.
Problems:
When I am adding an item to the list, it is not showing....
0
votes
3
answers
51
views
LiveData observer triggering previous response
In my login page when I click on login button with valid email and password, then it goes into homepage. and then when i logged out from there and redirect to login page . then i face is when i clicks ...
1
vote
1
answer
350
views
Update the count value in Column Item Android Jetpack Compose
Product Item Composable :
@Composable
fun ProductItem(product: Product, index: Int) {
val addProductViewModel = hiltViewModel<AddProductVM>()
val productSelectedIndex = remember { ...
1
vote
2
answers
1k
views
How to create singleton object and using for UI and viewmodel for two screen in kotlin jetpack compose?
I have a list like this
data class SelectedNtrItem(
val items:ArrayList<NutritionSearchItem> = arrayListOf()
)
I need to use this list on two composable screens, so I need to ...
0
votes
2
answers
82
views
How to make ViewModels communicate with same Model if I shouldn't in MVVM create Model in View?
Say, I have two Views. One is button, second is textView. When I click button, something changes in text. If I make it in MVVM, probably it should look like this:
There are button and text view which ...
0
votes
2
answers
822
views
How to implement RoomDataBase in An Activity using Dagger Hilt Injection in View Model
I'm trying to make an app that can enter and store Bible Verses. I'm using Dagger Hilt to inject my Daos into my View Model . My App keeps crashing whenever I try to use viewModel to get my state and ...
-1
votes
1
answer
220
views
Android: Model mapping in repository pattern
I want to fetch news from remote and map network response to entity class to store in room database in repository layer. i am using separate data class for both remote and database
Here are the data ...
0
votes
3
answers
3k
views
"Using ViewModel and LiveData Without Explicit Dependency Declaration in build.gradle"
I've noticed that in some of my Android projects, I'm able to access ViewModel and LiveData classes without explicitly adding the following dependencies to my build.gradle file:
implementation("...
0
votes
1
answer
81
views
How to get appModule properties in feature modules
My project is having feature1Module and feature2Module. These 2 are included in app module
build gradle file.
implementation project(":feature1Module")
implementation project(":...
0
votes
0
answers
64
views
MVVM Architecture Screen Rotation Issues
I have been trying to make a simple program where I will get data from Retrofit API calling into RecyclerView using MVVM architecture with JAVA, but I am not getting any data from Retrofit API into ...
0
votes
1
answer
95
views
Why Kotlin's collect function doesn't terminate itself?
When I download info from a DataBase the collect function doesn’t stop emission (Kotlin's collect function doesn't terminate itself.)
I have this entity class:
@Entity
data class ShareEntity(
@...
0
votes
0
answers
139
views
Two use cases which access the same repository - how to avoid identical/ duplicate API calls?
I have two use cases UseCase A and UseCase B which access the same repository Repo X. Repo X makes a API (data.com/getUserInfo) call to get certain data.
ViewModel 1 has need for only UseCase B, while ...
4
votes
2
answers
4k
views
Navigate using View Model in Jetpack Compose
Here is my MainActivity.kt file
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
NavigationHoster()
}
here is navhoster ...
0
votes
1
answer
99
views
I want to store and display highScore value on local device with .NET MAUI MVVM. Where and with what code snippet can I do this?
I'm developing a simple math practice game with .NET MAUI MVVM. I want the highScore value on the main page of the game to be updated after I close the application and re-enter it every time I play. ...
-1
votes
1
answer
98
views
The score I earned on the Game page with .NET MAUI MVVM is not visible on other pages. How can I keep score data in Local device
I want to display the score information I earned on the MultiplicationPage on the GameOverPage. I think I pulled the data from PlayerModal but it still doesn't show up.
GameOverPage.xaml
<?xml ...
0
votes
1
answer
71
views
Whether the answer is right or wrong, my score and counter are constantly increasing. Idont want this
Using the MVVM Design Pattern I am developing a basic operations math application.When I give a wrong answer, my score and counter score increase as if I answered correctly. I used some artificial ...
0
votes
1
answer
154
views
I made the property observable but it is not visible on the screen
In this application that I developed with MVVM, counter, question, score and answer were displayed on the screen before adding the Observable feature. When I added the Observable feature, these ...
0
votes
1
answer
128
views
Time, score and questions do not appear on the screen with .NET MAUI MVVM
MultiplicationPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="...
0
votes
1
answer
80
views
Clicking the Play button on the HomePage does not go to the GameSelectionPage
MauiProgram.cs
using MauiApp1.Sevices;
using MauiApp1.ViewModels;
using MauiApp1.Views;
using Microsoft.Extensions.Logging;
namespace MauiApp1;
public static class MauiProgram
{
public static ...
0
votes
1
answer
943
views
Not able to access SavedStateHandle from @Hilt ViewModel
I have two fragments, and I want to access the todoId from the ViewModel of the second fragment, but I am encountering issues while trying to access it.
Here is the problem I am facing:
E/...
0
votes
1
answer
77
views
How to update value every x seconds or when value from room database is changes
I'd like the variable listOfPoints to change every time when workout.points is changed or every "x" seconds.
var listOfPoints = emptyList<LatLng>()
var workoutId = viewModel....
1
vote
1
answer
1k
views
How can I call multiple APIs that are depending to each other's data, each response data must be used on the following API call?
//From Kotlin code (Compose View), using CoroutineScope
scope.launch {
viewModel.getDataOne(key)
viewModel.data_one.collect{ one ->
when(one){
is DataState.Success->{
...
0
votes
1
answer
2k
views
The communication between: A view, A viewModel, A useCase, A repository, A service, and A dao in a clean architecture (MVVM) for Android
Using the monarchy realm database, a dao gives liveData. A repository gives that liveData to a useCase as a flow using .asFlow on the liveData. The useCase needs to return the flow to a ViewModel ...
0
votes
1
answer
2k
views
How to test the ViewModel using Junit, Mockito and Kotlin flows in Android
I tried to test the ViewModel using Junit and Mockito, getting null pointer exception. It returns cannot invoke flow collector. I want to test the responses coming in MpinDataKey, check all parameters ...
0
votes
1
answer
471
views
error: cannot find symbol import com.example.databinding2.databinding.ActivityMainBindingImpl;
I'm unable to resolve this error.
I wanted to use two-way databinding in edittext.
Here is the code for the layout file.
<?xml version="1.0" encoding="utf-8"?>
<layout ...
0
votes
1
answer
853
views
Serialise json string with dynamic key to object in Kotlin
I am working on a requirement, where as when making a service call to the API, if it is success, the response object will be a set of key-value in the following format:
string : {string: string}
For ...
0
votes
1
answer
24
views
How to update UI from recyclerview custom listener class onScrollStateChanged?
My CustomScroll Listener class is .
This is separate class
class CustomScrollListener(): RecyclerView.OnScrollListener(){
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: ...
0
votes
1
answer
179
views
Where to place the MyFirebaseMessagingService file in Android project MVVM?
I have an Android project where I use MVVM. This is the structure:
src
\_ domain
\_ model
\_ repository
\_ ItemsRepository
\_ data
\_ repository
\_ ...
2
votes
2
answers
4k
views
Jetpack Compose: How good is having a separate ViewModel for every interactive component on Screen
I have chat like interface in Jetpack compose. Every message can either be Text, Audio, Video, or Image.
Each Audio message is displayed with the help of a AudioPlayer composable, and an attached ...
1
vote
1
answer
871
views
Database_Impl not implemented - MVVM Room Kotlin Android
I'm new here, grateful to meet you all here. I have an error like this based on my Logcat.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.voidcreativestation.toko/com....
0
votes
1
answer
63
views
How to change the text of customize button in a menu file with dataBinding?
I have a toolbar with a menu that contains a custom button at the end and I want to change the text of this button according to the fragment's position in a view pager. But when I call the function ...