https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
android-architecture
  • a

    akshay

    03/11/2020, 12:19 PM
    What are the benefits of using MVP and MVVM together?
    g
    s
    • 3
    • 2
  • o

    Ofir Bar

    03/11/2020, 5:25 PM
    Hey guys, Can anyone please post a short code example for the part marked in red? I didn’t understand what the author meant by “Presenter” and “the same scope as the view model”. Of course I can search for that on Google but I would like to get a code example exactly for the context marked in Red Source: https://medium.com/androiddevelopers/viewmodels-and-livedata-patterns-antipatterns-21efaef74a54
    s
    a
    +2
    • 5
    • 9
  • u

    ursus

    03/15/2020, 2:24 PM
    How do you pass in your mappers to view models or wherever? Are they just toplevel functions? Or objects extending a function? Do you pass them in via a ctor or use directly?
    a
    g
    • 3
    • 27
  • k

    Kavin

    03/16/2020, 2:41 PM
    I was going through the Android samples for Navigation Architecture. Can anyone tell me whats are the below dependencies for or where can I read about the differences?
    navigation.runtime = "androidx.navigation:navigation-runtime:$versions.navigation"
    navigation.runtime_ktx = "androidx.navigation:navigation-runtime-ktx:$versions.navigation"
    navigation.fragment = "androidx.navigation:navigation-fragment:$versions.navigation"
    navigation.fragment_ktx = "androidx.navigation:navigation-fragment-ktx:$versions.navigation"
    navigation.ui = "androidx.navigation:navigation-ui:$versions.navigation"
    navigation.ui_ktx = "androidx.navigation:navigation-ui-ktx:$versions.navigation"
    b
    d
    • 3
    • 3
  • s

    Steve

    03/16/2020, 9:34 PM
    When testing an MVVM setup (ViewModel, Repository, Data provider thingy), would it make sense to, in each of those things, validate that the Response object has the correct data in it, or just to make sure that it's getting the correct object?
    j
    • 2
    • 1
  • m

    Madalin Valceleanu

    03/18/2020, 8:20 AM
    📚 Android Sample App using modular, clean, scalable, testable Architecture written in Kotlin that presents modern 2019 approach to Android application development, latest tech-stack and best practices. Application is based, apply and strictly complies with each of the following 5 points: • A single-activity architecture, using the Navigation component to manage fragment operations. • Android architecture components, part of Android Jetpack give to project a robust design, testable and maintainable. • Pattern Model-View-ViewModel (MVVM) facilitating separation of development of the graphical user interface. • S.O.L.I.D design principles intended to make software designs more understandable, flexible and maintainable. • Modular app architecture allows being developed features in isolation, independently from other features. For more technical details please check the project readme. Project link: https://github.com/VMadalin/kotlin-sample-app
    a
    i
    v
    • 4
    • 15
  • a

    Ahmed Ibrahim

    03/20/2020, 10:53 AM
    I'm wondering in the Clean Architecture onion diagram. In which layer should the navigation and tracking be in? For the navigation it seems better to belong to the presentation layer, however it could also be part of the use case layer. As it could be part of a use case description "When a user clicks on a product, if the product is a collection then head to the collections screen, otherwise head to the product details screen" I'm curious what do experts think 🤔
    f
    s
    +4
    • 7
    • 25
  • u

    ursus

    03/30/2020, 6:32 PM
    When you modularize, and you need some shared code in each feature module
    o
    t
    d
    • 4
    • 20
  • o

    Ofir Bar

    04/01/2020, 7:41 PM
    Hey guys. In the following design, I have a BottomAppBar with 4 icons. Each icon, cause the screen to show a different Fragment, totalling 4 different Fragments (some screens have sub fragments in them). Currently, I created a variable "currentlySelectedFragment". Whenever an Icon is selected, that variable is changed causing the FragmentManager to replace the previously selected Fragment (thus killing it too) Do you think, that I should keep all of the 4 Fragments alive? as i perform replace, the next time I open that Fragment I need to do loading again. I wonder what is the best practice regarding Fragments here. Because on one side, I need to load the UI again everytime, on the other side I don't want to use too much memory.
    i
    • 2
    • 4
  • s

    Steve

    04/06/2020, 5:44 PM
    Why? That's what deep linking is for
    a
    • 2
    • 2
  • e

    emmax

    04/07/2020, 2:02 AM
    Are you describing like a master detail view? https://proandroiddev.com/master-detail-views-with-navigation-components-a20405f31974 There is also a Google code sample which shows how you can have a BottomNavigationView, with each top-level destination having its own navigation host and stack. https://github.com/android/architecture-components-samples/tree/master/NavigationAdvancedSample Not sure if either of those help. I'm not sure your exact scenario but thought I'd pass it along fwiw @Ahmed Mourad
    a
    • 2
    • 1
  • u

    ursus

    04/09/2020, 7:13 AM
    would you espresso or instrument unit test it?
    r
    d
    • 3
    • 6
  • a

    Ahmed Mourad

    04/11/2020, 7:23 AM
    How do you "bind" your LiveData objects to a corresponding TextView, if you're supposed to expose all your LiveData objects as immutables? (Without DataBinding)
    o
    r
    • 3
    • 140
  • u

    ursus

    04/13/2020, 9:10 AM
    Has anyone used protobuf for their rest apis?
    t
    s
    +2
    • 5
    • 10
  • u

    ursus

    04/15/2020, 12:54 AM
    should I use a webview or external browser? Isn't the point of it the delegating to a trusted 3rd party?
    s
    v
    +2
    • 5
    • 28
  • s

    Steve

    04/17/2020, 5:26 PM
    Is there a good guide for adding a debug mode to the app that would only be enabled during debug builds? Like say specifically for being able to switch web server endpoints and turning on something like MockWebServer?
    s
    • 2
    • 3
  • k

    Koya Sivaji

    04/19/2020, 1:52 PM
    One weird issue I am facing while using NavGraph. Whenever <- (back button) selected in toolbar, soft keyboard is not closed automatically. Seems a bug in AndroidX navigation. Has anyone faced this issue?
    e
    v
    • 3
    • 5
  • j

    julian

    04/29/2020, 7:09 PM
    Anyone here use Spotify's Mobius framework? I'm trying to get a sense of whether it has much traction outside of Spotify's internal use. (It's one of the contenders for unidirectional frameworks).
    b
    • 2
    • 2
  • b

    bhatnagarm

    04/29/2020, 8:53 PM
    Hey everyone, as showcased in Google samples making Repository class as Singleton seems to be bit confusing. So as per my understanding a Singleton class doesn't get Garbage collected as it's instance being stored into static variable. Doesn't this seems kind of anti-pattern. Until it's some common repository what's the use case for it to outlive it's scope which may be just within a smaller scope. So what do you guys think?? How many of you consider making Repository class as Singleton. If yes, then I'm really Keen to understand.
    s
    t
    a
    • 4
    • 12
  • r

    Rahul Ch

    05/01/2020, 4:23 PM
    Hi guys, I want to create a modular android app. The interaction to each module should be from the main App. For example If the Login module is called and once its job is done it should send back response to main app and main app should decide which module to be called... What is best architecture that I should follow to achieve this? Something like Uber Ribs.
    u
    • 2
    • 4
  • u

    ursus

    05/02/2020, 2:11 AM
    should viewmodel calculate this and emit a enum, or should it just provide the "raw" values from which view calculates it?
    r
    s
    • 3
    • 7
  • b

    BMG

    05/02/2020, 3:23 PM
    In Android presenter code, I see something like this, where
    isFetching
    is a class variable which holds network data fetching state. Is this a good pattern? I was trying to remove this class variable to reduce state in presenter. Is that possible or will it be an overkill?
    override fun fetchData() : {
      if(isFetching) return
    
      isFetching = true
      apiService
           .fetchData()
           .doOnFinally { isFetching = false }
           .subscribe({ 
              view?.updateData()
            }, { })
    }
    k
    • 2
    • 4
  • s

    Steve

    05/04/2020, 4:51 PM
    Using the NavigationComponent with a drawer, is there a way to programmatically show or hide some destinations? I have a module that should be in the Navigation Drawer, but not for everyone; only those users who have paid for the feature.
    e
    • 2
    • 2
  • s

    Slackbot

    05/10/2020, 8:29 AM
    This message was deleted.
    b
    • 2
    • 1
  • j

    Joan Colmenero

    05/11/2020, 6:54 AM
    Hello guys, I'm planning to create an endless scroll-view and I've found this Paging library from the Jetpack, looks very interesting but I do not get one thing, I'm used to from the repository do the mapper to the domain object, so from the use-case/inter-actor I have the domain object already done because I map it on the repository layer, my question is, dis data source that I have to create and this
    PageKeyedDataSource
    where is the correct layer to use it? Because I have to pass an object and don't know if it's the domain object or the response from retrofit.
    d
    • 2
    • 3
  • o

    oday

    05/12/2020, 9:17 PM
    hi, I have this code in my LoginViewModel https://hastebin.com/ujihufovil.kt and this code in my SignUpViewModel https://hastebin.com/uqilarefif.kt the functionality is duplicated and I’m not sure how to go about making them reusable and minimize the code as much as possible, I do know that validating the pattern checking for empty string and reacting to the results by setting the error message is doing too many things at once and that they should be separated but when I think of separating them I think then of having the same validateEmail (vaildatePassword) methods contain the new functions but still doing the 3 things at once, but now using functions ..how do I make this easier and not so jumbled?
    s
    r
    • 3
    • 10
  • s

    streetsofboston

    05/14/2020, 11:43 AM
    There is this love/hate relationship with DataBinding with us and hate seems to be winning out.... We started a project with just Coroutines and Flows. So far, so good. 😀
    💪 1
    s
    o
    • 3
    • 11
  • j

    jurajsolarml

    05/15/2020, 8:29 PM
    Hello, please help. I was beginner. What is wrong ? Android Studio 3.6.3,Kotlin 1.3.7.2, I've tried Refactor-Migrate-it Androidx, Clean Project, Rebuild Project, InvalidateCache / Restart multiple times it didn't help. https://pastebin.com/byj01tJe https://pastebin.com/bpVPuj72 https://pastebin.com/da2LePiK Error here: https://pastebin.com/uNi5EXFT https://pastebin.com/55x0xiFA Thanks
    k
    • 2
    • 2
  • o

    Orhan Tozan

    05/17/2020, 4:34 PM
    When using Koin/Dagger, is it usual to instantiate a repository on login and delete it on logout? Or maintain a single repository during the app's lifecycle, and clear it's cache when logging out?
    s
    g
    • 3
    • 3
  • j

    jayeshsolanki93

    05/18/2020, 4:59 PM
    Hi all. I have a question about MVVM architecture. Is there an apparent disadvantage to it?
    c
    o
    +7
    • 10
    • 31
Powered by Linen
Title
j

jayeshsolanki93

05/18/2020, 4:59 PM
Hi all. I have a question about MVVM architecture. Is there an apparent disadvantage to it?
Tbh I was asked this in an interview and I couldn’t come up with anything and we just discussed about how it does not have reference to the view and how sometimes one would add a livedataevent to handle simple clicks from the view to open a new screen.
c

Collin Flynn

05/18/2020, 7:17 PM
Depends on what they’re comparing it to. It has some overhead, which may be more or less than the alternatives considered in the interview.
o

Orhan Tozan

05/19/2020, 12:49 PM
@jayeshsolanki93 MVVM architecture by itself? Or implementing MVVM on Android? The ViewModel not having a reference to the view is not a disadvantage, that is one of the pro's. This way only the V in MVVM is framework dependent. Also no need for using livedata for events. I believe LiveData is built for showing state, events aren't states. Use Coroutines Flow for events.
All in all, I'm curious if those arguments were made by the interviewer or by you during the interview?
a

ahulyk

05/19/2020, 1:05 PM
LiveData and Flow are fine for events, imho. With LiveDate you just need to implement SingleLiveEvent
🇳🇴 1
👎 2
s

Saurabh

05/19/2020, 1:19 PM
I do have one thought, although not directly related to what MVVM is, but how I mostly see it implemented.
ViewModel
in my opinion does not have a view reference in it for a reason, that it is not bound by a view. I have an issue with how most applications I see have one
ViewModel
for each
View
in the architecture. That just makes it a presenter without a view reference. In my opinion, a
ViewModel
should be reusable, by any view that wants to show the data that a particular
ViewModel
exposes.
But by coupling it with each view, i.e, having
HomeActivity
with
HomeActivityViewModel
. We hinder that reusability part of it. The part of the issue is how even android studio suggest you to create
Fragment + ViewModel
through it's wizard.
➕ 1
o

Orhan Tozan

05/19/2020, 1:21 PM
@Saurabh I think it is normal for there to be both reusable and non reusable, usecase specific viewmodels. HomeViewModel should be okay, but it can reuse exposing some view states, such as button state etc.
s

Saurabh

05/19/2020, 1:24 PM
@Orhan Tozan I don't disagree with you. But if you think about it, a non-reusable ViewModel is just a presenter. I agree that it still doesn't have a view reference, but by coupling functionality, you can't use your ViewModel anywhere else.
o

Orhan Tozan

05/19/2020, 1:27 PM
I never used MVP myself, but from what I know is that Presenters are differnet in viewmodels in that viewmodels represent the current state of the view, while presenters do things more imperatively. E.g. in a login form, viewmodel would expose usernameTextInput: LiveData<String> to let the view know the current value of textfield, while the presenter in that case doesn't do that
s

Saurabh

05/19/2020, 1:42 PM
Yes you are absolutely right about how the data is driven in the case of both viewmodels and presenters. My case here is that since we already have separated out the view from the viewmodel, why couple it with functionality of a single view. I think we can achieve much more effective reusability if we don't do this.
d

dewildte

05/19/2020, 7:45 PM
SingleLiveEvent is an Anti Pattern. The correct tool is some kind of stream that can be subscribed to.
Flow
is good for this.
.NET has the best implementation of MVVM IMHO. I encourage all to look at it.
A strong emphasis is put on Events and Commands in the .NET MVVM.
But MVVM is not an architecture, it is just a pattern that is part of the solutions overall architecture.
a

Anastasia Finogenova

05/21/2020, 3:46 AM
If trying to answer the question there is no "apparent" disadvantage to MVVM itself. If you read articles on these architectural pattern they always conclude MVVM is the most "advanced" variation of a layered architecture vs MVP and MVC which had an apparent disadvantage of tight(er) coupling with View
u

ursus

05/21/2020, 2:55 PM
If you stop thinking about ViewModels as special, the big picture will start to make more sense. What we call viewmodels are just (usually) screen scoped components. Not different from some other domain logic object, which just happens to live in a wider (app) scope
only difference is scope it lives in, which should be transparent
a

Andrew

05/21/2020, 8:40 PM
You can get a decent answer on this just google "mvvm pros and cons". The first disadvantage for me that came to mind was sometimes very simple things can seem overly complex but this is kind of true for any real architecture. Displaying a toast for example, its easy to just have the VM do it but that is incorrect, you need to use some sort of single event mechanism and the obvious choice was even stated in this thread is a bad idea and your left not knowing what to do. In practice a lot of similar things come up where you know how to do something, just not with MVVM even though you are stuck using MVVM... which is still the best in my opinion.
o

OG

05/21/2020, 10:19 PM
IMO the saying "there is no such thing as a perfect system" holds true here. Typically with MVVM you have your view (activity/fragment), VM (obvious) and a repository (or w/e you call it). VM is suppose to be where you hold state + business logic. the view should be very minimal. And your repository is where you do your networking/data layer logic plus maybe mapping of data model -> UI model. But what happens when you start throwing all your business logic into a VM? It ends up being very similar to the old days where you just kept everything in a single activity/fragment file. Typically you will hear, well create another presenter or something similar to break down the logic in your VM... And for me that's where it gets confusing. What's the point? The other is VM, at least in Android world, doesnt work well with single events. I know there's a bunch of ways to handle single emitted events, but it just doesn't sit right with the idea of VM on Android. The whole point is for the VM to hold data that that doesn't get destroyed and recreated like your view, which can happen for many reasons, so that the data is preserved and immediately ready without having to load again. And again we say VM serves the purpose of state + business logic. Well it doesn't fit 100% with actions that are taken only once or events that are supposed to only happen once. I probably over explained that a ton but I'm like on my 6th ☕ today and I'm currently running in place 😂😂😂😂
😅 1
a

Anastasia Finogenova

05/21/2020, 10:21 PM
I think VM is fine on Android. When it gets "fat" it is an issue buy I think you should have an Interactor/Use case along with Viewmodel so you can have presentation logic in VM and business logic in the Interactor
o

OG

05/21/2020, 10:27 PM
@Anastasia Finogenova yes exactly. When it starts getting polluted is when I scratch my head a bit. Also another thing that comes to mind and what I ee on projects I work on is the disagreement between if the the VM should be bound to a specific view or if it should be built in a way where it can be reused by any view, which ultimately might mean there might be some "business logic" in your view layer.
a

Anastasia Finogenova

05/21/2020, 10:30 PM
I don't understand how it can be reused if it holds specific presentation logic to that screen. I am for single responsibility principle If there is a need to share state in between your screens you can have a single shared Viewmodel. That is the recommended way to communicate between Fragments now for example. But why would you want to reuse it for every view? You can potentially have a base Viewmodel if you have generic logic to provide to multiple views that you are going to inherit from (I have seen that) or you can create extension funs to be used across multiple VMs as an option too
If your concern is code duplication so you try to have one ViewModel
o

OG

05/21/2020, 10:40 PM
Well let's say you have a view that has state which is driven off of data from API #1. And two other views which also have their UI driven off of data from APi #2 and #3 respectively. And let's say you have a bunch of flags that come down from API #4 that drive the state of a common toolbar component. And let's say you have three activity views which all should follow the same logic for their toolbar but they all show different ui components. One way to go about it Is creating a single viewmodel to be used for the toolbar business logic. And a different view model for each activity that holds the business logic for the rest of their UI. And then second approach is you have just a total of 3 VMs, 1 for each activity, which may hold redundant business logic for the shared toolbar component. This is just a quick idea I came up with that I think may paint the picture I'm trying to describe... Not sure.. 🤔
Updated/edited my comment to be more clear
I prefer the first approach, where each activity would have a total of 2 VMs. One for the shared toolbar and one for their own UI. But I come across some folks who try to follow the single VM -> single view approach since that's what it looks like in common Android tutorials/code labs/documentation.
a

Anastasia Finogenova

05/21/2020, 10:46 PM
I think single view + single VM is just a simplification in the tutorial
👍 1
o

OG

05/21/2020, 10:46 PM
Yes I agree.
a

Anastasia Finogenova

05/21/2020, 10:47 PM
There can totally be one shared ViewModel If there is a case for it. But in now if you follow the single activity pattern such thing as a toolbar logic can reside in your activity VM
o

OG

05/21/2020, 10:49 PM
Yes absolutely 👍. I think we are probably saying the same thing. I was just trying to bring to light the argument/debate that I get/see often when it comes to what logic should live in the ViewModel.
👍 1
View count: 5