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

    Sudhir Singh Khanger

    06/07/2021, 4:20 AM
    What is the effect using
    NonCancellable
    in the following case? Would it outlive the scope and finish the job?
    viewModelScope.launch {
        withContext(NonCancellable + <http://Dispatchers.IO|Dispatchers.IO>) {
             // some job
        }
    }
    g
    • 2
    • 2
  • j

    James Black

    06/07/2021, 4:36 AM
    I am using KMP, kotlin 1.4.32, and on android using compose beta06. When I upgrade to beta08 I get errors due to my kotlin compiler flags. For that area where compose and kotlin intersect where should I ask my question? Here or somewhere else. I am nervous about using discuss.kotlinlang as I expect it will be flagged again.
    a
    a
    • 3
    • 4
  • s

    Sudhir Singh Khanger

    06/07/2021, 6:32 AM
    I am a little fuzzy on why the following method
    someDbCall()
    should be a
    suspend
    function.
    private fun someDbCall() { //some db call }
    someScope.launch {
        someDBCall()
    }
    Do you have a personal philosophy such as don't use suspend keyword unless the compiler forces you to as I have been reading on Stack overflow?
    someScope.launch {
        withContext(NonCancellable + <http://Dispatchers.IO|Dispatchers.IO>) { someDBCall() }
    }
    If you do have a philosophy of not using suspend keyword when not needed then how does construct like withContext affect using them with non-suspend keyword function.
    g
    c
    • 3
    • 9
  • h

    haris mehmood

    06/07/2021, 9:15 AM
    Hi everyone, MVI is better than MVVM ?
    :not-kotlin: 5
    c
    a
    +3
    • 6
    • 9
  • a

    Ankit Dubey

    06/07/2021, 9:30 AM
    Can we define method return type as generic. something like this
    suspend fun <T> commonPost (query: HashMap<String, String>, mUrl : String) : DataState.Success<T> {
            val mClient = KtorClientFactory().build()
            val res = <http://mClient.post|mClient.post><MemberResponse>("${baseURL}$mUrl")
            return DataState.Success(res)
    }
    I want to create a generic method that will call multiple APIs using ktor.
    • 1
    • 1
  • r

    Ranjan Rukhaya

    06/07/2021, 10:33 AM
    How to download a pdf from a url and save in internal storage of app ?
    :not-kotlin: 6
    s
    z
    a
    • 4
    • 3
  • m

    Marcello Galhardo

    06/07/2021, 3:02 PM
    Does anyone know a benchmark between Parcelable and KotlinX Serialization ProtoBuffs? Does it make sense to use KxS ProtoBufs as a replacement for Parcelables? 🤔
    d
    • 2
    • 2
  • s

    solidogen

    06/07/2021, 4:15 PM
    Paging: let’s say I have a RemoteMediator backed by room dao. If I make a manual change to a single item in database, will updated pagingData be emitted? e.g. marking item as favourite
    :not-kotlin: 2
    d
    d
    • 3
    • 117
  • m

    melatonina

    06/07/2021, 11:17 PM
    Do people feel that
    StateFlow
    is a good replacement for
    LiveData
    on Android? There is often a noticeable delay in updates, which leads to the UI to represent incorrect information when it first shows up. That never happened to me with
    LiveData
    .
    m
    g
    +2
    • 5
    • 7
  • b

    brian

    06/08/2021, 6:14 AM
    Hi everyone I want to split my app and break it down to different modules. Is this an advisable pattern
    :not-kotlin: 2
    h
    • 2
    • 1
  • s

    Slackbot

    06/08/2021, 6:29 AM
    This message was deleted.
    g
    • 2
    • 1
  • m

    Marko Novakovic

    06/08/2021, 8:02 AM
    2 files found with path 'META-INF/AL2.0'.
    this started to appear all of a sudden in my project. why? what does this mean?
    g
    • 2
    • 2
  • y

    y9san9

    06/08/2021, 2:23 PM
    Hi mates, I'm making a module in my multiplatform library, and now I am trying to create this module with 
    build.gradle.kts
    . Here is how my build file and
    buildSrc
    looks like, everything builds OK, but I have highlighting issues. Maybe the problem is my runtime classpath contains the dependency while compile classpath doesn't. So does anyone know how to inspect this?
    j
    • 2
    • 11
  • m

    Mert Demir

    06/08/2021, 5:31 PM
    👋 I’m here! What’d I miss?
    👋 4
    :not-kotlin: 7
    z
    c
    g
    • 4
    • 4
  • v

    Vivek Modi

    06/09/2021, 10:41 AM
    Hey i want to add items in array list using getter in kotlin. Can someone explain what i am doing wrong here.
    private var categoryType = arrayListOf<CategoryType>()
        get() {
            if (category1List != null) {
                field = arrayListOf(CategoryType.Category1)
            }
    
            if (category2List != null) {
                field = arrayListOf(CategoryType.Category2)
            }
    
            if (category3List != null) {
                field = arrayListOf(CategoryType.Category3)
            }
            return field
        }
    enum class CategoryType(val valueName: String) {
        ALL("ALL"),
        Category1("Category1"),
        Category2("Category2"),
        Category3("Category3");
    
        companion object {
            fun getArray(): List<CategoryType> {
                return values().map {
                    it
                }
            }
        }
    }
    j
    z
    • 3
    • 3
  • s

    Sivan

    06/09/2021, 2:56 PM
    Have a question regarding Play Console and testing tracks. Is this the right channel? Don't want to be in the wrong place 😅
    :not-kotlin: 6
    a
    • 2
    • 1
  • h

    haris mehmood

    06/10/2021, 7:26 AM
    Hi mates, i just want to ask ...which one is better live data or Kotlin flows? why? with proper reasons. Thanks
    j
    • 2
    • 1
  • v

    Vivek Modi

    06/10/2021, 2:23 PM
    I want to pass parameter in function but it giving error  This syntax is reserved for future use; to call a reference, enclose it in parentheses: (foo::bar)(args). Also i want to make a genric runFunction which can take any parameter i.e. Int, String etc. In this example code i am sending sumInt(2) to runFunction also i want to send concatenateString("John"). Anyone Know how to achieve this.
    z
    • 2
    • 3
  • m

    Mary Owuor

    06/11/2021, 5:19 AM
    How can I list togather with data class in kotlin
    g
    • 2
    • 5
  • s

    Slackbot

    06/11/2021, 8:45 AM
    This message was deleted.
    📚 1
    l
    • 2
    • 1
  • l

    Law Gimenez

    06/11/2021, 9:05 AM
    Hello friends, I’m experiencing NullPointerExceptions on my fragments when I migrated it to ViewBinding. I am following exactly based on the documentation https://developer.android.com/topic/libraries/view-binding#kts but it will throw NullPointerException on the
    private val binding get() = _binding!!
    line. Thanks in advance for the help!
    w
    f
    j
    • 4
    • 11
  • v

    Vinícius Santos

    06/11/2021, 12:47 PM
    Hi there, is there any way a can rum multiple coroutines in parallel then resume when all of then are completed ? Something like that.
    viewModelScope.launch {
        launch { a = one() }
        launch { b = two() }
        print(a+b)
    }
    s
    e
    r
    • 4
    • 8
  • c

    Caio Costa

    06/11/2021, 8:19 PM
    Hello folks. Let's say i have a method to check internet connection inside my ViewModel that's something along these lines: internal fun callToCheckIfInternetConnectionIsAvailable( onConnectionAvailable: () -> Unit = {}, onConnectionUnavailable: () -> Unit = {} ) { if(networkChecking.checkIfInternetConnectionIsAvailable()) { onConnectionAvailable() } else { onConnectionUnavailable() } } And then i pass something like this from my Activity: viewModel.callToCheckIfInternetConnectionIsAvailable({ onConnectionUnavailable = { Toast.makeText(applicationContext, "Bla", Toast.LONG).show() } }) When it is passed to my ViewModel, it will be interpreted as a method since it's wrapped by a lambda. Although that is true, the content inside that lambda, contains lifecycle-related references such as a View. Could passing this instruction to a ViewModel cause a memory leak if the LifecycleOwner(Activity/Fragment) gets destroyed in the meantime? And besides that, would it break the MVVM pattern? Really curious to know your thoughts on the matter. Thank you in advance :kotlin-intensifies:
    c
    s
    s
    • 4
    • 10
  • b

    Bilagi

    06/13/2021, 10:38 AM
    Is
    Activity Results API
    stable for production use?
    g
    a
    m
    • 4
    • 8
  • l

    Lilly

    06/13/2021, 12:32 PM
    In an Android project what's the purpose of
    kotlinOptions.jvmTarget
    ? I'm wondering because we don't write Java Code so what prevents me to set it to
    16
    ?
    c
    g
    • 3
    • 7
  • r

    rajesh

    06/13/2021, 6:18 PM
    How to use jetpack datastore with retrofit interceptor to append header on every request? Datastore doesn't seem to support return type without Flow api.
    u
    m
    • 3
    • 2
  • c

    Caio Costa

    06/13/2021, 6:57 PM
    Hello folks, how are you doing? Hope you're doing great. So i have these two classes:
    class MainActivity : AppCompatActivity() {
    
        private val viewModel: MainViewModel by viewModels()
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
    
            runTaskOnBackground {
                viewModel.errorStateFlow.collect {
                    println("CALLED")
                    Toast.makeText(applicationContext, "$it", Toast.LENGTH_LONG).show()
                }
            }
        }
    
        private fun runTaskOnBackground(task: suspend () -> Unit) =
            addRepeatingJob(Lifecycle.State.CREATED) {
                task()
            }
    }
    
    ////////////////////////////////////////////////////
    
    internal class MainViewModel : ViewModel() {
    
        private val _errorStateFlow = MutableStateFlow(0)
        val errorStateFlow: StateFlow<Int>
            get() = _errorStateFlow
    }
    The problem i'm getting is that both the Toast and the println i declared are being shown even without posting a value to that MutableStateFlow inside my ViewModel because the value I'm getting is the same as the default one. Looks like the MutableStateFlow is posting the default value automatically. Do you know why this is happening and if there's a way to avoid that? I've searched across the internet but couldn't find someone with the same problem. Thank you in advance :kotlin-flag:
    l
    • 2
    • 2
  • r

    Ramprasad

    06/13/2021, 7:04 PM
    https://github.com/rramprasad/BloomApp/blob/main/app/src/main/java/dev/ramprasad/bloom/AppNavigation.kt
    l
    • 2
    • 1
  • r

    Ramprasad

    06/13/2021, 7:04 PM
    How to use scaffold and nested graph in jetpack compose
    z
    • 2
    • 1
  • l

    Law Gimenez

    06/14/2021, 6:10 AM
    Hi friends, is my
    buildToolsVersion
    correct? If yes it is currently throwing an error
    Installed Build Tools revision 31.0.0 rc5 is corrupted
    :not-kotlin: 5
    g
    • 2
    • 5
Powered by Linen
Title
l

Law Gimenez

06/14/2021, 6:10 AM
Hi friends, is my
buildToolsVersion
correct? If yes it is currently throwing an error
Installed Build Tools revision 31.0.0 rc5 is corrupted
:not-kotlin: 5
g

gildor

06/14/2021, 6:14 AM
I believe it’s not necessary specify build tools version explicitly on recent android gradle plugin
☝️ 3
l

Law Gimenez

06/14/2021, 6:17 AM
What do you mean? I just downloaded from the SDK Manager their latest Android SDK Build-Tools 31-rc5
g

gildor

06/14/2021, 6:23 AM
I mean that you can remove buildToolsVersion line and no need to download it explicitly Android Gradle Plugin will download required version automatically
l

Law Gimenez

06/14/2021, 6:26 AM
Whoa thanks, let me try. Will that automatically use build tools 31?
g

gildor

06/14/2021, 6:45 AM
it will use what is required for this version of target sdk (not more, not less)
➕ 2
View count: 2