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

    Gabriele Rugani

    05/14/2021, 12:40 PM
    Hi ! I will try to repost my question 😕
    What could happen if I would use different libraries with different kotlin version ?
    
    Do you update your project's kotlin language's version only when all the imported libraries are updated ?
    🇳🇴 3
    e
    c
    • 3
    • 25
  • a

    alenz316

    05/14/2021, 5:37 PM
    Just ran into a runtime crash after updating to 1.5.0 with an Android Emulator running on API 16:
    E/AndroidRuntime( 3715): Caused by: java.lang.NoClassDefFoundError: kotlin.collections.EmptyList
    E/AndroidRuntime( 3715):        at kotlin.collections.CollectionsKt__CollectionsKt.emptyList(SourceFile:71)
    E/AndroidRuntime( 3715):        at kotlin.collections.CollectionsKt.emptyList(SourceFile)
    E/AndroidRuntime( 3715):        ... 16 more
    However, this crash does not happen on newer versions of Android (API 29) or if we have
    kotlinOptions.useOldBackend = true
    , any idea what's the underlying cause in the new IR back-end that would cause it to crash on older versions of Android?
    e
    • 2
    • 13
  • u

    Ujjwal Mittal

    05/14/2021, 5:47 PM
    Hey everyone, I recently study about advantages of using single activity in an app. so while building my own app I started to wonder if it is recommended to have login/signup fragment and home screen in a single activity. if anyone has any opinions on this, please share. Thank you in advance. 🙂
    :not-kotlin: 3
    c
    n
    • 3
    • 7
  • h

    Hekanksh Gohel

    05/15/2021, 10:35 AM
    I am about to start developing but before that i want to take knowledge about it, can you guys guide me for the same please? Any platform for that?
    :google: 6
    :not-kotlin: 6
    z
    n
    • 3
    • 7
  • c

    Colton Idle

    05/16/2021, 4:48 AM
    I haven't really kept up to date with flow as a replacement for LiveData. I use LiveData currently to connect my AAC ViewModel to my Fragment. I looked up some quick articles and it seems like I would replace my LiveData usage of:
    private val _name = MutableLiveData("")
       val name: LiveData<String> = _name
    with StateFlow like this
    private val _name = MutableStateFlow("")
        val name: StateFlow<String> = _name
    Is that pretty much it? I do plan on reading/learning more about it, but I'm just trying to get a POC done and just wanted to make sure I'm not breaking any rules here that I don't know about. Cheers
    a
    t
    +2
    • 5
    • 12
  • i

    Ink

    05/16/2021, 4:16 PM
    How to create only one instance of ViewModel for my @Composable screen? Now every time when I call my @Composable, new ViewModel is created.
    @Composable
    fun BankScreen() {
        val viewModel: BankViewModel = viewModel()
    }
    Tried to follow https://insert-koin.io/docs/reference/koin-android/compose/ but Android Studio throws weird error
    l
    • 2
    • 5
  • o

    onirutlA

    05/16/2021, 11:09 PM
    Are there hot reload in android native kotlin for android studio 4.2, if there aren't so when we get hot reload?
    c
    • 2
    • 2
  • s

    spierce7

    05/17/2021, 3:46 AM
    Does anyone know how to apply anti-aliasing to an image while downsizing it in Android? I’ve tried every answer I can find on SO or in blogs, and nothing seems to work.
    a
    • 2
    • 3
  • s

    spnda

    05/17/2021, 11:51 AM
    For general android development, should I use jdk7 or jdk8?
    u
    m
    • 3
    • 7
  • m

    melatonina

    05/17/2021, 2:32 PM
    Hello. Can we bind to StateFlow<T> with a binding adapter? How should I write the adapter? I wrote an adapter taking T and an adapter taking StateFlow<T>. It does not work
    g
    • 2
    • 1
  • s

    Slackbot

    05/17/2021, 2:37 PM
    This message was deleted.
    :java: 3
    :stackoverflow: 1
    😔 1
    🇳🇴 1
    👎🏻 1
    😑 2
    😂 1
    👎 4
    :not-kotlin: 8
    👎🏼 1
    k
    l
    • 3
    • 10
  • i

    Ink

    05/18/2021, 1:00 PM
    Is it possible to simplify this code?
    private fun setActiveLabel(textView: TextView) {
        binding.apply {
            accounts.isSelected = binding.accounts == textView
            cards.isSelected = binding.cards == textView
            loans.isSelected = binding.loans == textView
            funds.isSelected = binding.funds == textView
    
            accounts.isActivated = binding.accounts == textView
            cards.isActivated = binding.cards == textView
            loans.isActivated = binding.loans == textView
            funds.isActivated = binding.funds == textView
        }
    
        when (textView) {
            binding.accounts -> { binding.accounts.setFocusForAccessibility() }
            binding.cards -> { binding.cards.setFocusForAccessibility() }
            binding.loans -> { binding.loans.setFocusForAccessibility() }
            binding.funds -> { binding.funds.setFocusForAccessibility() }
        }
    }
    b
    • 2
    • 3
  • e

    Erik

    05/18/2021, 2:06 PM
    I use the 'shell scripts' feature from the JetBrains Toolbox (JBT) a lot. I think that since the Android Studio (AS) 4.2 upgrade it started behaving differently: - ⬅️ Before, when running
    studio .
    (e.g. in a repo root) it would open AS in that directory. Running it again would open the existing AS project window. - ➡️ After, when running
    studio .
    it opens the project in a new AS window every time, even if there already is an open window for the project. This is an issue, because during the day I run
    studio .
    quite often and I end up with too many windows for the same project! Do you have this problem too? Do you know how to fix this? Is this and AS or JBT issue?
    • 1
    • 2
  • i

    Ink

    05/18/2021, 3:41 PM
    How I can pass my
    NavHostController
    as lambda down? I tried:
    val appNavController = rememberNavController()
    
    composable("loginScreen") {
        LoginScreen(::appNavController)
    }
    @Composable
    fun LoginScreen(navigateToLoginDetails: (details: String) -> Unit) {
        ....
          navigateToLoginDetails(details)
        ...
    }
    j
    • 2
    • 2
  • i

    Ilyes Dhiaeddine Belmiloud

    05/18/2021, 7:36 PM
    Hi I'm trying to convert jetpack compose to imagebitmap is that possible thanks in advance
    👀 1
    a
    • 2
    • 1
  • i

    Ink

    05/19/2021, 5:42 AM
    How I can change JDK location for my project? I use Android Studio Canary version and there is no option to change it in project structure tab.
    z
    n
    j
    • 4
    • 12
  • h

    haris mehmood

    05/19/2021, 10:08 AM
    Hi can anyone help me show network error to user when wifi is connected but no internet access like youtube?
    t
    д
    • 3
    • 2
  • r

    Ryan Simon

    05/19/2021, 10:14 PM
    Has anyone ever come across a UI issue submitted by a user where UI elements are just bizarrely missing from the layout? I can't reproduce an issue a user from a Samsung Galaxy S8 has sent me where entire ui elements are missing. I've tested display sizes, text sizes, and more but still no way to reproduce it.
    z
    d
    b
    • 4
    • 23
  • a

    Abhishek Dewan

    05/20/2021, 5:18 AM
    Quick question regarding the new Splash Screen API(https://developer.android.com/about/versions/12/features/splash-screen). Since this was added in android api 12 would this mean that we would have to write our own splash screens for Android 11 and below and then rely on this API to either hide our splash screen or hide the system generated splash screen ? Anyone have a good stratergy in mind for handling this ?
    :not-kotlin: 2
    • 1
    • 1
  • j

    Joost Klitsie

    05/20/2021, 8:33 AM
    hi everyone! I have a question: If I have a
    lifecycleScope
    and I want to run some job that either runs after a certain time or event (so can get cancelled) what is the best way of doing so? For example, using:
    val job = supervisorJob()
    val myScope = lifecycleScope + job
    
    // Somewhere else
    job.cancelChildren()
    Is not working out, because the
    myScope
    stays alive after the `lifecycleScope`is cancelled Using
    var job: Job? = null
    val theWork = lifecycleScope.launch {
        // delay, do the work
    }
    
    // Somewhere else
    job?.cancel()
    This would work, but then I always have to keep track of the job. Is it possible to have a lifecycle respecting scope on which I can cancel its children when necessary?
    d
    • 2
    • 21
  • d

    Denis Capkovic

    05/20/2021, 12:09 PM
    Hi, is there a way of controlling the position of Keyboard on screen? We are modifying the Window manager with 
    wm overscan
    , to hide navigation controls all-together (you cannot swipe down to bring up notification shade). But this also moves the keyboard, and hides part of it. Our application is always in landscape and is the only one running. Hacky solutions are welcome.
    t
    • 2
    • 4
  • u

    ursus

    05/20/2021, 6:17 PM
    Do you guys memcache database query Flows/Observables via `replayingShare`/`shareIn` and friends?
    g
    • 2
    • 2
  • a

    Android75

    05/21/2021, 2:21 AM
    I have some problem with suspend in a Interceptor. I use a interceptor to refresh token:
    @Singleton
    class RefreshInterceptor @Inject
    constructor(
     private val savePrefSecurity: SavePrefSecurity
    ) : Interceptor {
       
        override fun intercept(chain: Interceptor.Chain): Response {
    
           
            var request = chain?.request()
            var response = chain!!.proceed(request)
               if (response.code == 401) {
                var refresh = savePrefSecurity.getSValue(REFRESH_TOKEN)
                if (!refresh.isNullOrBlank()) {
                    )
                    GlobalScope.launch {
                        var refrehResponse = api.refreshToken(sendRefresh)
                        [....}
                        // other code...
                         return@let intercept(chain)
                    }
                }
    }
       return response
    1. how can i avoid GlobalScope ? because refreshToken is a supend function 2. i think that return@let intercept(chain) is inappropriate blockin
    ➕ 1
    l
    a
    o
    • 4
    • 3
  • j

    Jesus Cruz Victoria

    05/21/2021, 4:25 AM
    Hi goodnight, do you know how I can share my login data saved in my application with another application? Grettings
    h
    • 2
    • 3
  • m

    Marco

    05/21/2021, 8:10 AM
    Hey people, I’ve got a question about collecting the state from the VM in compose: which one of these is best practice to follow?
    private val _uiState: MutableStateFlow<UiState> = MutableStateFlow(State.loading())
        val uiState: StateFlow<UiState> = _uiState
    
        init {
            viewModelScope.launch {
                repository.getData()
                    .map { resource ->
                        Log.d("VM", "got $resource")
                        State.fromResource(resource)
                    }
                    .collect { state -> _uiState.value = state }
            }
        }
    or
    val uiState = repository.getData()
            .map { resource ->
                Log.d("VM", "got $resource")
                State.fromResource(resource)
            }
            .stateIn(
                scope = viewModelScope,
                started = WhileSubscribed(5000),
                initialValue = State.loading()
            )
    And calling them from the activity
    val state by viewModel.uiState.collectAsState()
    I am also noticing some heavy delay when the api is executed:
    I/Choreographer: Skipped 136 frames!  The application may be doing too much work on its main thread.
    a
    • 2
    • 2
  • s

    Slackbot

    05/21/2021, 1:02 PM
    This message was deleted.
    :not-kotlin: 2
    a
    k
    • 3
    • 3
  • e

    Ernestas

    05/21/2021, 1:57 PM
    Hi guys, I am in a situation that our backend team is unable to provide us with a paginated endpoint for a large dataset. Any tips/articles on how to handle huge json responses with coroutines/flow? (I’m using retrofit for networking)
    a
    v
    • 3
    • 6
  • b

    Bill

    05/22/2021, 9:45 AM
    Hello, how could I convert the bellow Swift code to Kotlin? I'm coming from iOS and I use a Redux implementation for state management ("state")
    state.list = state.list.map { listItem in
            if listItem.id == action.payload.id {
                var listItem = listItem
                listItem.title = action.payload.newTitle
                return listItem
              } else {
                return listItem
              }
            }
    k
    m
    • 3
    • 7
  • c

    Christopher Elías

    05/23/2021, 4:20 AM
    Hi everyone. I just updated the jetpack navigation library from from
    2.3.5
    to
    2.4.0-alpha1
    but all my actions are throwing error in the generated class. It its something like this...
    i
    • 2
    • 2
  • d

    dhananjaykulkarni19

    05/23/2021, 6:50 PM
    Dear fellow developers What is the best practice to insert record in room db ? (With and without Kotlin) AsyncTask Rxjava Coroutines (if using Kotlin) Thread pool executor
    😒uspend: 1
    :google: 2
    :not-kotlin: 2
    g
    • 2
    • 1
Powered by Linen
Title
d

dhananjaykulkarni19

05/23/2021, 6:50 PM
Dear fellow developers What is the best practice to insert record in room db ? (With and without Kotlin) AsyncTask Rxjava Coroutines (if using Kotlin) Thread pool executor
😒uspend: 1
:google: 2
:not-kotlin: 2
g

gaeltshilombo

05/24/2021, 7:53 AM
I have a preference for Coroutine, I use this way on the project I am working, it is easy and safe.
👍 2
View count: 6