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
  • s

    Sergio C.

    10/31/2021, 3:04 PM
    Hello everyone, is there a way to make paging display always a fixed number of items? I have a Realtime database which can reach thousands of items so it's not good idea to keep loading items to memory and make the app slow. Also I need to search/filter items by phone number in the entire list from the Realtime database. Is there something like this already done? How could I do this? I'm thinking of using Room to store all the items from DB so I can search easily. Now the part of keeping a fixed number of elements in the pager I don't have an idea.
    j
    s
    e
    • 4
    • 9
  • u

    ursus

    11/07/2021, 12:36 PM
    people who use anvil or hilt for di how do you deal with object composition? how to "uninclude" the default implementation from base type binding, but then have it available as parameter for the extended type?
    m
    m
    • 3
    • 2
  • h

    Hakob Astvacatryan

    11/10/2021, 3:30 PM
    Hey folks, we are investigating Anvil as a DI solution. How do you make injection easer for Activities or Fragments?
    m
    • 2
    • 4
  • v

    vesp

    11/11/2021, 7:11 PM
    Maybe this is my natually skeptical nature but is Google's iosched repo the absolute best repo to turn to for Android archictecture best practices? Is there another repo that has...even better best practices?
    m
    a
    +2
    • 5
    • 11
  • l

    Lilly

    11/15/2021, 5:44 PM
    From a gradle point of view my project structure looks like: Project A (android app) -> Project B (android library) <- Project C (android library) So instead of having a multi module project I have a bunch of standalone projects that are published separately. I ran into some problems and was overthinking this approach and I don't know why I went this path in the past (I guess I didn't know how to publish modules in a mm project). Since we can publish modules in a multi module project (so they can be shared with other projects) wouldn't it be better to got with a multi module project. I can't see any benefit with having a lot of single projects. Are there any advantages disadvantages between these approaches?
    j
    d
    • 3
    • 4
  • a

    Alex C

    11/17/2021, 3:37 AM
    Hey folks, using jetpack Navigation, I can add enterAnim and exitAnim in the navigation action, but how can I add animation when using navigationUp()?
    g
    • 2
    • 2
  • m

    mattinger

    11/17/2021, 9:27 PM
    For anyone using hilt, our app has a really big graph at the moment (a ton of modules). We’re considering using hilt in our libraries first, and would need to get objects from our existing component into the SingletonComponent. I tried creating a bridge module which would pull from our singleton components’ holder to get the objects. However, it seems when i switch from the dagger to the hilt compiler, it’s not generating my existing components. If i have both, i get an error that it can’t find some MemoizedSential internal class. Has anyone even tried this before?
    k
    c
    u
    • 4
    • 5
  • u

    ursus

    11/25/2021, 1:03 AM
    Do you guys drop database columns? Its extra annoying to do the temp table nonsense
    b
    m
    • 3
    • 7
  • u

    ursus

    11/27/2021, 3:27 AM
    Has anyone worked on some purchase flow? Any smarts on how to handle branching etc? Unless your fragment 1 just replaces it self with fragment 2 etc
    a
    • 2
    • 1
  • p

    psk

    12/01/2021, 1:29 AM
    I am trying a vanilla MVI for my new project with channels and flow. I’ve used RxJava before and tried some frameworks like Mvrx, Grox. I have few questions I’d like to get answers for and see how this situations are handled.  1. Two ui intents are mapped to async calls but they should be emitted sequentially so that the UI updates are sequential. For example event A and B are emitted, async operation trigged by event B finishes before event A. But the state updates should be sequential right?  2. On-off async operations or side effects like uploading or downloading a pdf. This needs to only show a snackbar and there is no state preserved. 3. Suggestions for state loss problems or back pressure?
    r
    • 2
    • 4
  • l

    Lilly

    12/04/2021, 3:10 PM
    Hi, how would you name a class that acts as a single entry point to a library and is glue for multiple objetcs with different responsibilities. It's like a summary of multiple little APIs that form a greater API that is exposed to the client. My first thought was a
    Facade
    . Any ideas?
    d
    u
    g
    • 4
    • 3
  • m

    mattinger

    12/08/2021, 7:38 PM
    So i’m trying to use anvil to build a 3 layer application graph where different libraries can contribute. I plan on having a shared set of scopes: • ApplicationScope • ActivityScope • FragmentScope I can use ContributesTo to add inject methods to the scopes, but i’m curious what’s the best way to get hold of the actual instances, since the host app would be the one that would know about the actual factories. I was thinking of defining the components in the library as well, but not running the anvil compiler there and instead just running it in the host app.
    u
    • 2
    • 5
  • n

    Nacho Ruiz Martin

    12/18/2021, 6:47 PM
    Hey! 👋 Given a classic MVI approach with Jetpack’s
    ViewModel
    , how would you share some logic between different
    ViewModels
    ? I have a 1:1 relationship between screens and VM and the latest is in charge of any change to the state. So a lot of logic may be shared, for example the management of a textfield with value update, validation, error setting and such.
    w
    k
    • 3
    • 3
  • m

    mattinger

    12/21/2021, 3:01 AM
    I’m having a bit of an issue with compose (see pictures in thread). I have full page content with buttons anchored at the bottom. When i click in a text field, the keyboard is appearing and pushing the buttons up, which ends up shrinking the column the input text is in, and pushing into the scrollable area offscreen.
    • 1
    • 5
  • s

    Sergio C.

    12/25/2021, 11:00 PM
    Using MVVM and clean code how should I create the connections to the ViewModel in the scenario where I need to have the Context to be able to show several Dialogs in a process when the user performs an action? Imagine the user clicks a button to create a document, in this process I need several inputs from the user, for that I need to pass the Context to show a dialog to select items, or choose yes, no or other options etc, creating a document has it’s business logic but the issue is it’s not a one shot operation where the user clicks and waits for the result, it’s a back and forth View to business logic. Passing the Context to the ViewModel it’s the easy way but I think is not a great idea and it should create memory leaks, creating an observer in the activity for every user interaction in the process of creating a document is going to be messy and confusing… Any other good options to solve this? Or a project sample with the same kind of logic?
    m
    m
    m
    • 4
    • 10
  • u

    이준학

    12/28/2021, 2:50 PM
    I am currently developing an android service app. A problem arose while developing a foreground service app. This is the situation when the activity gets data from the service. One way is to use a bind service and call a method from the service instance.
    Another way is to get data using intents.
    
    I've searched a lot, but almost all of them are using intents. If the lifecycle fits well, isn't it convenient and good to call a function as a bind service? I'd like to hear your opinion.
    (In the service, it does not actually work, but creates and manages a working thread.)
    f
    • 2
    • 3
  • s

    Sanendak

    12/29/2021, 4:19 PM
    Hello everyone! I have a question about collecting data from multiple data sources into one list. I have two sources: remote and local. Models for these items almost the same except several fields. It's okay to merge them into one source for viewmodel? In that case new shared model will have several null fields. Or I should collect data separately and not merge models? In the list local items always placed first. Thanks.
    ✅ 1
    m
    w
    +2
    • 5
    • 5
  • u

    ursus

    01/05/2022, 4:54 AM
    Is it needed to sequentialize data sync? sync contains api get + db write. Db writes are synchronized. So only way this can get messed up if the 2nd concurrent sync arrived sooner than 1st Is this really relevant for production? Should I put Mutex everywhere?
    g
    j
    • 3
    • 35
  • u

    ursus

    01/07/2022, 4:16 PM
    How do you think the spotify year review story animations are made? giant lottie files per page?
    m
    • 2
    • 1
  • d

    dave08

    01/09/2022, 12:45 PM
    Should a DI framework be handling which implementation to give for each platform, or should that always be delegated to a factory method?
    c
    k
    g
    • 4
    • 13
  • a

    Arpan Sarkar

    01/12/2022, 2:27 PM
    Our app single activity architecture using androidx navigation. Now the multiple language support will roll out in phases. For the time being some fragment need to support localization (with RTL for some languages) and some fragments need to show English only how can i archive this ? On app local is forced to be English
    class App : Application() {
        private var baseCtx: Context? = null
        private var appCtx: Context? = null
        private var baseRes: Resources? = null
    
        override fun attachBaseContext(base: Context) {
            val ctx = baseCtx ?: base.createLocalizedContext(Locale.ENGLISH).also {
                baseCtx = it
            }
            super.attachBaseContext(ctx)
        }
    
        override fun getApplicationContext(): Context {
            return appCtx ?: super.getApplicationContext().createLocalizedContext(Locale.ENGLISH).also {
                appCtx = it
            }
        }
    
        override fun getResources(): Resources {
            return baseRes ?: baseContext.createLocalizedContext(Locale.ENGLISH).resources.also {
                baseRes = it
            }
        }
    }
    I am planing to do some thing like this for fragments which requires translation not sure if its a good idea or not
    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
        ): View {
            val themedContext = ContextThemeWrapper(
                inflater.context,
                R.style.Theme_LocalizedFragment_Green // apply brand them green
            )
            val local = getLocal() // get local from local storage
            if (requiredTranslation) {
                themedContext.applyOverrideConfiguration(
                    requireContext().createLocalizedConfiguration(local)
                )
            }
            val themedInflater = inflater.cloneInContext(themedContext)
            return super.onCreateView(themedInflater, container, savedInstanceState).apply {
                // adjust layout direction as per local
                ViewCompat.setLayoutDirection(this, TextUtilsCompat.getLayoutDirectionFromLocale(local))
            }
        }
    m
    • 2
    • 2
  • c

    Cicero

    01/16/2022, 5:20 PM
    Hello people, I keep getting messages in arguments about project architecture like: "it's a matter of preference" and I often answer with ''it's a matter of engineering". I can't discuss opinions that are based on "liking things", I need arguments like "improves readability, testability, performance, organization". For me, There must be some explanation of why things are being done. Maybe I'm a bit obsessive here but this kin d of argument was use too often to sneak in things that this developers often can't even understand (the "is a matter of preference" answer comes here). Please shed light on my ignorance. This was the message I got when I questioned the use of interfaces in use cases:
    Hey Cicero,
    Using interface is a matter of Clean Code Architecture, so yes we are using interfaces with UseCases. Please whenever you need to add a new one make sure that you do an interface for.
    This project is intended to be big and continues project, so if we are going to support Unit test in future then we need to make sure that we can test each part separately.
    The ViewModel is the only exception at the moment because Koin does not accept interfaces when we define the ViewModel. If we you know a way then please tell me to add interfaces to ViewModels.
    So, I understand why I would use interfaces in repositories, right, mocking and what not, but aren't use cases supposed to represent business rules that will shape the information in your view? And aren't this business rules supposed to be prime to the functionality of your viewmodel? Also, what about adding interfaces everywhere when no code is tested or "it's going to be teste in the future"? This kind of discussion eat me inside last year.
    j
    c
    +4
    • 7
    • 17
  • l

    luke_c

    01/22/2022, 10:59 PM
    If you have a use case e.g. SearchUserUseCase and the UI should only go into a loading state when some validation passes, e.g. search term more than 3 characters, then where would you put that validation? It can't go in the UseCase because the ViewModel has to set the loading state before calling it but the validation could fail If it goes in the ViewModel then that validation logic becomes something you need to copy to all other places that use your UseCase. That's probably the best option, but if the validation was more business critical then what would you do? Separate use case for validation?
    k
    v
    • 3
    • 2
  • t

    takahirom

    01/28/2022, 1:33 AM
    I am using Guide to app architecture as a reference for my development. Thank you! One issue that often comes up in my development team is whether to throw Exceptions or use Results when designing with suspend functions and Flows. I think there are advantages and disadvantages to both. 1. The advantage of using Exception is that you don't forget to convert it to Result. You can use a coordinated error mechanism in Kotlin coroutines.
    suspend fun fetch(): List<Item>
    2. The advantage of using Result is that you can specify the type of error and ensure that the API user can handle it.
    suspend fun fetch(): Result<List<Item>, FetchError>
    In the architecture guide, there is a statement that you should use Kotlin's error mechanism. Is it to take advantage of this?
    For coroutines and flows, you should use Kotlin's built-in error-handling mechanism.
    https://developer.android.com/jetpack/guide/data-layer?hl=en#expose-errors
    ➕ 1
    o
    a
    g
    • 4
    • 14
  • c

    Colton Idle

    01/28/2022, 6:18 PM
    I think that'd be a good question for #coroutines or #flow
    t
    • 2
    • 1
  • c

    Can Korkmaz

    02/06/2022, 6:24 PM
    Can anyone check if I'm doing something wrong with instantiating a viewmodel? here is the code:
    @Preview
    @Composable
    fun LoginScreenPreview(){
        val navController = rememberNavController()
        val main: MainActivity = MainActivity()
        val myfactory = MainViewModelFactory(Database.getInstance(main.applicationContext).Dao, main.application)
        val viewModel: MainViewModel = viewModel(
            factory =myfactory
        )
        //TextField(value ="xxx", onValueChange ={} )
        LoginScreen(navController,  viewmodel = viewModel)
    }
    and viewmodel factory:
    class MainViewModelFactory(
        private val dataSource: Dao,
        private val application: Application
    ): ViewModelProvider.Factory{
        @Suppress("unchecked_cast")
        override fun <T : ViewModel> create(modelClass: Class<T>): T {
            if (modelClass.isAssignableFrom(MainViewModel::class.java)) {
                return MainViewModel(dataSource, application) as T
            }
            throw IllegalArgumentException("Unknown ViewModel class")
        }
    }
    The login screen only has basic fields such as textfields and a button, but uses data from viewmodel. Can't preview anything as of this state.
    f
    • 2
    • 5
  • l

    Lokik Soni

    02/07/2022, 7:53 AM
    I am new to Android Clean Architecture and trying to implement it in my project. But in my project I need: 1. Broadcast receiver to show Battery details 2. RingtoneManager to show the list of Ringtones in activity. So here I am confuse in which layer should I put all these stuff like if I put BroadcastReceiver in Data layer then how to register it with activity context. And can I put RingtoneManager data layer which also require context.
    k
    • 2
    • 2
  • c

    Can Korkmaz

    02/15/2022, 2:31 PM
    The single MainActivity which extends ComponentActivity, which also hosts navigation composable, has the same lifecycle as the application right? I need the main activity to live throughout the application lifecycle since I do login and I want a val loginUser in ViewModel (MainActivity) to persist till process death.
    a
    t
    • 3
    • 7
  • a

    Arun Joseph

    02/15/2022, 8:53 PM
    Is it possible to create a short lived android viewmodel within another larger viewmodel? For example, i have a view model for a view, I would like to create a new view model that lives from start button to stop button within the view.
    t
    f
    • 3
    • 12
  • g

    Gomathi Gms

    02/16/2022, 4:30 PM
    Friends, how to find list of 3rd party liberty used in my Android app in the android studio
    s
    • 2
    • 5
Powered by Linen
Title
g

Gomathi Gms

02/16/2022, 4:30 PM
Friends, how to find list of 3rd party liberty used in my Android app in the android studio
s

Stuie

02/16/2022, 6:03 PM
Look in your app's build.gradle file to see any explicit dependencies. There's a
dependencies
block. You can get more information by running Gradle's
dependencies
task via
Ctrl
Ctrl
gradle dependencies
g

Gomathi Gms

02/16/2022, 6:04 PM
So external lib and third party lib are same
s

Stuie

02/16/2022, 6:08 PM
Yeah, third party would be a library written by someone not at your company, e.g. Retrofit, Dagger, OkHttp, Firebase, Facebook Login, etc. Assuming you don't work for one of the companies that wrote those libraries. 🙂
https://en.wikipedia.org/wiki/Third-party_software_component
g

Gomathi Gms

02/16/2022, 6:13 PM
Thanks @Stuie
View count: 4