https://kotlinlang.org logo
Docs
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
  • l

    loloof64

    02/09/2021, 5:46 PM
    Hi everybody. What layout should I use if I want to implement something like in a sms application ? I mean • the dates are printed in the center • the incoming messages are on the left • the outcoming messages are on the right Is it possible to achieve something like this with a RecyclerView and a
    StaggeredGridLayoutManager
    (or
    LinearLayoutManager
    ) ?
    o
    a
    • 3
    • 6
  • a

    André Thiele

    02/09/2021, 7:39 PM
    Is it possible to register multiple registerForActivityResult callbacks in a fragment? or is it possible to distinguish between multiple requested permissions?
    b
    i
    • 3
    • 10
  • d

    Dustin Lam

    02/09/2021, 8:02 PM
    I believe this should be fixed in the next release.. can you test against snapshots and see if it resolves your issue?
    l
    • 2
    • 3
  • d

    Dustin Lam

    02/09/2021, 8:02 PM
    androidx.dev is down atm, but you should be able to point to
    j
    • 2
    • 1
  • d

    Dustin Lam

    02/09/2021, 8:03 PM
    maven { url "https://ci.android.com/builds/submitted/7134699/androidx_snapshot/latest/repository" }
    l
    • 2
    • 2
  • j

    Jørgen Heinsen

    02/10/2021, 8:13 AM
    Does anyone know if it is possible to contact the android team notifying them about errors in their documentation? I have used this codelab on navigation in january, but now I just get a 404. https://codelabs.developers.google.com/codelabs/android-navigation/ They link to it from their documentation still, so I cannot help but think it is a error.
    k
    • 2
    • 1
  • b

    buszi0809

    02/10/2021, 2:08 PM
    Hi, does anyone know if there is any library to test Paging 3? The only library I've found is "androidx.paging:paging-common" but there is literally 0 information, guide or documentation for it, does anyone know if they finally implemented any testing library for Paging 3?
    d
    • 2
    • 5
  • s

    Stian Brandt

    02/10/2021, 3:33 PM
    After removing jcenter() as a repository, I get the following error when i try to run ./gradlew lintDebug. I assume this means trove4j does not exist in either google() or mavenCentral()
    Execution failed for task ':app:lintDebug'.
    > Could not resolve all files for configuration ':app:lintClassPath'.
       > Could not find org.jetbrains.trove4j:trove4j:20160824.
         Searched in the following locations:
           - <https://dl.google.com/dl/android/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom>
           - <https://repo.maven.apache.org/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom>
         Required by:
             project :app > com.android.tools.lint:lint-gradle:27.1.2 > com.android.tools:sdk-common:27.1.2
             project :app > com.android.tools.lint:lint-gradle:27.1.2 > com.android.tools.external.com-intellij:intellij-core:27.1.2
    👀 1
    s
    v
    • 3
    • 3
  • t

    Tiago Nunes

    02/10/2021, 3:41 PM
    Hi everyone, when using PagingData.map() from Paging 3, i'm getting a Compile Time Error: The feature "suspend conversion" is disabled wih the hint: set module language to 1.4 But I'm using Kotlin 1.4.30 ...
    • 1
    • 1
  • a

    André Thiele

    02/10/2021, 7:26 PM
    Anyone else having this lint error in Android Studio? (im using canary 5)
    a
    s
    • 3
    • 6
  • a

    André Thiele

    02/10/2021, 9:50 PM
    How should I write my SQL Room Query if I only want to include visits where is_deleted = 0? (The normal … AND visits.is_deleted = 0 does not work) (Given that CustomerWithVisits has an embedded customer entity and relationship on visits)
    @Transaction
    @Query("""
      SELECT * FROM customers
      WHERE customer_id = :id
      AND is_deleted = 0
      """)
    fun getCustomerWithVisits(id: Long): Flow<CustomerWithVisits>
    p
    • 2
    • 1
  • h

    harry248

    02/11/2021, 2:41 PM
    I am curious - is there a lightweight solution that detects edges (of a document) in a video frame / image that doesn’t depend on OpenCV (which is way too large)? Something like CIDetector (with CIFeatureTypeRectangle) on iOS?
    :stackoverflow: 3
    i
    • 2
    • 2
  • s

    Slackbot

    02/11/2021, 2:44 PM
    This message was deleted.
    a
    • 2
    • 1
  • n

    Niklas Gürtler

    02/12/2021, 11:08 AM
    Idea for the Linter: Hint about replacing
    withContext(Dispatchers.Main) { invalidate() }
    with
    postInvalidate()
    a
    z
    • 3
    • 22
  • s

    Susheel

    02/12/2021, 6:02 PM
    We are using the YoutubePlayerSDK to play youtube videos in our app but I realized that requires the device to have youtube installed on it. I've heard of exoplayer. Does anyone if it's a good alternative? I'm looking for the ability to show thumbnails, subtitles too.
    :stackoverflow: 2
    :google: 2
    j
    s
    • 3
    • 3
  • t

    TarunY

    02/13/2021, 3:58 AM
    i have added proGuard rules but sill issue persist
    r
    • 2
    • 2
  • f

    Florian

    02/13/2021, 2:47 PM
    Are there situations when
    viewLifecycleOwner.lifecycleScope.launch
    (instead of
    launchWhenStarted
    ) would crash if it collected a value while the app is in the background?
    i
    • 2
    • 2
  • a

    André Thiele

    02/13/2021, 4:30 PM
    how to migrate from PreferenceManager.getDefaultSharedPreferences() to DataStore Preferences?
    :stackoverflow: 3
    :google: 2
    • 1
    • 3
  • a

    André Thiele

    02/13/2021, 7:16 PM
    Instead of just reacting with StackOverflow emojis one could take the time and try to understand the questions…
    e
    k
    +2
    • 5
    • 13
  • d

    dazza5000

    02/14/2021, 1:41 AM
    does anyone know why they use R to specify the generic type here instead of T? https://github.com/android/architecture-samples/blob/a6156ad6bb0888aa60bdd587a8886[…]/example/android/architecture/blueprints/todoapp/data/Result.kt
    i
    v
    • 3
    • 8
  • c

    Chetan Tuteja

    02/15/2021, 4:55 AM
    Since JCenter is going to be deprecated, what is the next best choice? I don't think anyone uses JitPack do they?
    n
    v
    h
    • 4
    • 9
  • b

    Bhaskar

    02/15/2021, 5:58 PM
    does any one know how to get okHttp:v4.9.0 working on android 4.2 device. I am not able to fetch the apis using it.
    :stackoverflow: 2
    j
    • 2
    • 3
  • k

    kenkyee

    02/16/2021, 12:40 AM
    @hhariri can we rename this channel #android-kotlin-issues or #android-kotlin-stuff or #kotlin-on-android?
    👍 1
    o
    h
    • 3
    • 5
  • a

    Alex

    02/16/2021, 1:07 AM
    Please help a newbie 🙏 This allows me to create a value in a database (firebase) but if the editText value is left empty, my app crashes. Is there a way for me to replace the
    null
    value this throws when left empty with a default value like a
    0
    ?
    val caloriesPerServingEditText = findViewById<EditText>(R.id.caloriesPerServingEditText)
                val caloriesPerServing = caloriesPerServingEditText.text.toString().toInt()
    
                database.child(addFoodName).setValue(FoodData(caloriesPerServing))
    j
    a
    m
    • 4
    • 9
  • u

    Utkarsh Tiwari

    02/16/2021, 4:58 AM
    Hi everyone, I seem to be getting this error when trying to build my project:
    org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call '<get-current>' into
    public val DsColors: com.iamutkarshtiwari.ds.theme.DsColorPalette defined in com.iamutkarshtiwari.ds.theme in file DsTheme.kt
    val DsColors: DsColorPalette
        @Composable
        get() = AmbientDsColor.current
    Cause: Not generated
    Any ideas what went wrong?
    a
    • 2
    • 2
  • b

    Bilel El Oud

    02/16/2021, 7:35 AM
    Hi everyone, i am new and i started reading the language programming kotlin so i want to know how i can read Android with kotlin (the courses to read ...) Thanks for all 😃
    u
    b
    • 3
    • 3
  • s

    Samir Basnet

    02/17/2021, 10:55 AM
    When using kotlin extension function, is it possible to initialize some value inside the extension function only once ( like does lazy work inside extension function) and not create instance every time i call extension function??
    k
    g
    l
    • 4
    • 11
  • k

    Kshitij Patil

    02/17/2021, 11:45 AM
    I’ve a list as part of state (data class) I’m maintaining inside a viewModel. This state is being observed by the UI components and updated accordingly. I also want to be able to edit/delete an element from this list but I can’t make the list mutable (As UI is supposed to consume it as immutable list) so everytime I need to do any modifications on that list, I go through
    val newEntries = currentState().subEntries.toMutableList()
    newEntries.remove(action.subEntry)
    setState { copy(subEntries = newEntries.toList()) }
    Are there any performance hits by doing it this way?
    e
    • 2
    • 4
  • d

    Dan Halperin

    02/17/2021, 5:23 PM
    Any senior Kotlin devs in the US looking for contract work? Lyft is building a new flagship app and looking for two Android devs to join the launch team. DM me for more details
    👎 2
    m
    • 2
    • 1
  • r

    Rechee Jozil

    02/18/2021, 5:33 AM
    I'm curious... for those who work at a tech company where there's some sort of "architecture", where does threading fit into all that? I'm curious at what layer in your architecture you switch threads (if you switch at all :)). Also, how are your threads set up? Do you have your own thread pools? Do you use given thread pools (Like
    <http://Dispatchers.IO|Dispatchers.IO>
    in coroutines)? Do you do things asynchronously or more blocking? Damn I got a lot of questions haha
    ➕ 1
    s
    o
    +3
    • 6
    • 7
Powered by Linen
Title
r

Rechee Jozil

02/18/2021, 5:33 AM
I'm curious... for those who work at a tech company where there's some sort of "architecture", where does threading fit into all that? I'm curious at what layer in your architecture you switch threads (if you switch at all :)). Also, how are your threads set up? Do you have your own thread pools? Do you use given thread pools (Like
<http://Dispatchers.IO|Dispatchers.IO>
in coroutines)? Do you do things asynchronously or more blocking? Damn I got a lot of questions haha
➕ 1
s

Shabinder Singh

02/18/2021, 5:37 AM
I would like to see source code of a large scale app with millions of user base and a whole team working/developing it .... I would like to see how things in android dev work altogether in a large scale app , is it or is it not the same as a normal app , what extra practices they use if any.... And i believe see something in action answers more questions than we had at the moment , we learn more..... If anybody knows of anysuch such project's repo , i would be very grateful!
👍 1
o

OG

02/18/2021, 6:59 AM
I work in multiple code bases, some really really large and some that are small/simple. The architectures are pretty close, mainly MVVM, some with a flavor of MVI. But what is consistent across all these codebases in terms of threading, is that all methods within the view (activity/fragment) and ViewModel are main-safe. That is, you can call all methods safely on main thread and won't block the UI. Using the repository/useCase pattern, public methods contained in this classes should also be main safe. It's recommended to pass the different dispatchers into your repo/useCase classes so you can easily test as well. But the main thing to point out here is that all public methods are main-safe. Thread switching (using Dispatchers.IO, Dispatchers.Default etc) is contained within the repository/use case classes. Whether it be calling some remote data source, db, or data processing etc. Coroutines and some helpful extensions like viewModelScope make this all clean and easy to achieve. So an example would be a suspend method loadUsers in the repo, which is main-safe, since it internally uses withContext to switch to Dispatchers.IO for loading users. I'm probably giving an over simplification here but I think you get the picture I'm trying to paint 😊. Idk if this exactly answers all or some of your questions.. 2a.m. here and I'm struggling to fall asleep haha but my brain is a bit fried atm. Just came across this and thought I'd share what I typically do. Edit: just want to clarify that what I explained above is more a general pattern. It's acceptable to use Dispatchers.Default for example, even in your ViewModel. I think the most important rule is more that any public method is main-safe. And if you follow the architecture j described above, the view will be as dumb/simple as possible, so there is no need to handle thread switching in the view layer. The ViewModel contains straightforward business logic, such as retrieving data from repo layer and managing/updating a state, so there's really no need to handle thread switching here as well. Which then brings the last part which is your data/repo layer. Which basically exposes public main-safe APIs, but internally that is where thread switching/if any, is typically happening. Which is typically the case, fetching data from web service, local db, mapping Backend models etc. Hope that clears up any additional confusion.
👍 1
v

Valtteri Puonti

02/18/2021, 8:11 AM
We use
Executors.newSingleThreadExecutor().asCoroutineDispatcher()
on our use case layer to make sure that domain objects are not modified concurrently, otherwise, normal coroutine stuff you see everywhere: IO for IO, UI for UI etc..
👍 1
z

Zach Klippenstein (he/him) [MOD]

02/18/2021, 2:29 PM
I work on a pretty large codebase, and most code isn’t concerned about threading. Retrofit handles threading for network requests, and we do database operations on a different thread (we use a single background “file” thread for most DB ops). But most of our business logic is ran on the main thread - we actually try to get back there as quickly as possible, @Ray Ryan gave a

talk▾

about why some years ago. We use the standard Rx schedulers and coroutine dispatchers, but all access to them is done via injection with dagger. Certain features have specific, unique threading requirements and they do their own thing, but that’s rare.
➕ 1
👍 1
j

Joost Klitsie

02/19/2021, 11:51 AM
For coroutines I think it is best-practice to have the place where the work is happening take care of threading. For example, if you have Room you should be able to interact with coroutines and room from the main thread, because room will internally switch to IO. Same goes for retrofit and it SHOULD work like this with other libraries as well
doesn't mean all libraries cohere to this best-practice
even though they should
View count: 5