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

    Michael Bernier

    03/26/2019, 4:08 PM
    if you don't want problems, run AS stable (3.3.2)
    👎 3
    👍 1
    l
    • 2
    • 3
  • a

    Adam Kirk

    03/26/2019, 4:16 PM
    So I noticed that a lot of developers will use $module in there gradle so they don’t have to update the number in multiple places. However since android studio has this really nice feature where it lets you know when there is a new version of something (but this breaks when you use the $module approach. Just wondering is there a reason people dont just put the number and allow android studio to tell them there is an update, is it normally bad to update the gradle dependencies on an app, I would have thought it would always be best to be on the latest version of each dependency? thoughts?
    c
    b
    • 3
    • 6
  • a

    Adam Kirk

    03/27/2019, 1:13 AM
    If anyone that really knows JUnit 5, Room, Unit Testing and Testing the Dao please let me know(i could really use some guidance 30 mins or so) 🙂 I had it all working in JUnit 4 but because 5 doesnt use Rules I cant get my test to work right now.
    i
    • 2
    • 3
  • m

    morcerfdumas

    03/27/2019, 7:44 AM
    Anyone used the Fuel library? This one https://github.com/kittinunf/fuel.
    g
    • 2
    • 1
  • m

    morcerfdumas

    03/27/2019, 7:48 AM
    I’ve checked all of the superclasses and dependencies, and didn’t find any abstract property of that name. There is, however, a
    val body: String?
    property on the
    FuelRouting
    interface
    i
    r
    • 3
    • 3
  • a

    Adam Kirk

    03/27/2019, 4:02 PM
    Hey everyone should it be
    android {
        defaultConfig {
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    }
    or
    android {
        defaultConfig {
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner4"
        }
    }
    or
    android {
        defaultConfig {
            testInstrumentationRunner "androidx.test.ext.junit.runners.AndroidJUnit"
        }
    }
    ???
    c
    • 2
    • 2
  • a

    Adam Kirk

    03/27/2019, 5:20 PM
    Ok I feel like I am doing something wrong. I have this “All In App” thing that I can run https://imgur.com/a/E4hnH47 which runs all my unit tests both in test and android Test however if any of them fail (which some do) I run them on there own sometimes they pass and sometimes they dont. if they dont and I change something I have to run them individually then I can run the All In App to see the changes??? Also why do they sometimes work and sometimes not?
    k
    c
    • 3
    • 22
  • l

    Lilly

    03/27/2019, 5:53 PM
    Hi, I'm trying to setup a channel producer like explained here (https://kotlinlang.org/docs/reference/coroutines/channels.html) - keyword: coroutines - but I don't know how I have to use a scope so that the
    produce
    method is available within `scan`:
    @ObsoleteCoroutinesApi
        @ExperimentalCoroutinesApi
        @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
        fun scan(filters: List<ScanFilter>?, settings: ScanSettings): ReceiveChannel<ScanResult> {
            requireSafeSettings(settings)
            return produce(context) { // unresolvable reference
                val scanResultsChannel = Channel<ScanResult>(capacity = UNLIMITED)
                val scanCallback = ScanCallback(scanResultsChannel)
                scanner.startScan(filters, settings, scanCallback)
                scanResultsChannel.consumeEach { send(it) }
                scanResultsChannel.invokeOnClose { scanner.stopScan(scanCallback) }
    
                if (SDK_INT >= O_MR1 && scanCallback.isScanningTooFrequently()) {
                    scanResultsChannel.close(ScanFailedException(SCAN_FAILED_SCANNING_TOO_FREQUENTLY))
                }
            }
        }
    I call this method within
    ScannerLiveData
    class that extends from LiveData:
    fun startScan() {
            if (isScanning) {
                return
            }
    
            scanChannel = scanner.scan(null, settings)
    
            scanChannel.consumeEach {  // unresolvable reference
                // Todo
            }
    
            isScanning = true
        }
    My
    ScannerLiveData
    object gets injected in my
    ScannerViewModel
    where I simply call
    startScan()
    . I don't know how to provide a scope to use the
    scan
    method. I know there is a predefined
    viewModelScope
    ...The only idea I have is to pass this scope down to
    scan
    method. Can someone help?
    t
    l
    • 3
    • 20
  • l

    LeoColman

    03/27/2019, 8:40 PM
    However, KotlinTest has Android in the near-future roadmap
    t
    s
    • 3
    • 5
  • l

    Lilly

    03/27/2019, 8:45 PM
    ok nice. I have a component that should die with my fragment. Should I instantiate this component in application as singleton and provide it in my fragment or should I instantiate it in fragment everytime it is started? @jw oh the question isn't Kotlin specific at all ^^ but I would appreciate some help
    t
    g
    a
    • 4
    • 8
  • s

    Shan

    03/28/2019, 9:12 AM
    Hey all. Anyone have any insight as to why
    R
    is giving me an unresolved reference error? edit: The solution was to downgrade the Android Gradle Plugin to 3.2.1 from 3.3.0 in Intellij, as there were some breaking changes that were not brought over.
    Untitled.kt
    j
    g
    +5
    • 8
    • 34
  • p

    paulex

    03/28/2019, 11:21 AM
    I'm about using
    ButterKnife
    for view binding, i wanted to confirm if there is another(better) alternative provided by google itself?
    s
    l
    +4
    • 7
    • 10
  • a

    ar-g

    03/28/2019, 11:28 AM
    hey, this code is throwing NPE, any ideas why?
    fun ConnectivityManager?.isConnected(): Boolean {
        return this != null && activeNetworkInfo != null && activeNetworkInfo.isConnected
    }
    Fatal Exception: java.lang.IllegalStateException: activeNetworkInfo must not be null
    a
    m
    p
    • 4
    • 7
  • s

    Shan

    03/28/2019, 6:30 PM
    Does anyone know when the Android Gradle plugin will let me upgrade to Gradle 5.3.1? Keep getting this error when I try to sync after upgrading
    Gradle sync failed: Unsupported method: IdeaModuleDependency.getDependencyModule()
    . Am I doing something wrong here? It seems like other people are using Gradle v5.0+ .. 🤔
    a
    r
    l
    • 4
    • 9
  • j

    jw

    03/29/2019, 1:20 AM
    set
    archivesBaseName
    in each module to something unique
    j
    • 2
    • 1
  • w

    wbertan

    03/29/2019, 10:01 AM
    Trying to understand few things... Was trying to create an extension:
    fun View.setOnClickListenerWithThrottle(@Nullable listener: View.OnClickListener?) {
            // body
        }
    Was planning to use like the Android `setOnClickListener`:
    // This is the Android 'public void setOnClickListener(@Nullable OnClickListener l)'
            view.setOnClickListener {
                //onClick action
            }
    But I'm getting this error:
    /*
                Type mismatch.
                Required: View.OnClickListener?
                Found () -> Unit
            */
            view.setOnClickListenerWithThrottle {
                //onClick action
            }
    Any idea or suggestion? Someone knows why or how I could achieve the desired behaviour?
    g
    a
    j
    • 4
    • 10
  • d

    Damien O'Reilly

    03/30/2019, 7:28 PM
    Hi, anyone have issues when using databinding, and viewmodel's with mutable live data objects and fragments? e.g. on device rotate, I get
    onCreateView
    called twice, and 2nd time, my mutable live data is blank/fresh
    s
    l
    • 3
    • 6
  • m

    maheswar

    04/01/2019, 2:07 PM
    Hi any one written unit tests for coroutines with launch and async
    f
    • 2
    • 6
  • j

    Justin

    04/01/2019, 8:51 PM
    Perhaps I’m mistaken or uninformed, but it does look like there are times when the Kotlin property syntax is misleading: e.g. I’m writing some code to cancel jobs via JobScheduler, and so in Kotlin I have the following code:
    val jobScheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as android.app.job.JobScheduler
    jobScheduler.allPendingJobs
    where
    jobScheduler.allPendingJobs
    is property syntax for the abstract method
    JobScheduler#getAllPendingJobs
    Initially I figured I’m just accessing a member variable of the
    JobScheduler
    (apparently abstract) class but when I dive into
    JobScheduler
    , I noticed that
    allPendingJobs
    is actually an abstract method, which, for all I know, is doing some intensive work and has not already done that work I guess what I’m asking is, why does Kotlin and/or the IDE use property syntax on abstract methods? or am I misunderstanding what “property syntax” means? or…? Thanks for your time!
    l
    g
    • 3
    • 4
  • s

    Slackbot

    04/02/2019, 8:59 AM
    This message was deleted.
    :stackoverflow: 7
    :google: 4
    r
    f
    • 3
    • 2
  • a

    Adam Kirk

    04/03/2019, 12:50 AM
    Does this make sense? The assetRepoImpl checks the database first and assigns the currentUser then checks the server (When appropriate) and updates the currentUser on the observer. I need access to the currentUser inside the AssetRepo to get the Assets. So I am looking to see if this is the best way / right way?
    class AssetRepositoryImpl(private val assetDao: AssetDao,
                              private val assetAPIDataSource: AssetAPIDataSource,
                              userAPIDataSource: UserAPIDataSource,
                              userDao: UserDao
    ) : AssetRepository {
    
        private lateinit var currentUser: User
    
        init {
            //Check the database first
            userDao.getCurrentUserLiveData().observeOnce {
                println("ObserverOnce In AssetRepo Impl ${it.token}")
                currentUser = it
            }
    
            //When there is an update then update here
            userAPIDataSource.downloadedCurrentUser.observeForever {
                currentUser = createUser(it)
            }
    
            assetAPIDataSource.downloadedCurrentAssets.observeForever { newCurrentAssets ->
                persistFetchedCurrentAssets(newCurrentAssets)
            }
        }
    I should note that it works. 🙂 but just because something works doesn’t mean its right and yes I am aware that there is lots missing for proper understanding. hopefully most will be able to understand what I am trying to do. In essence I need a way to access the user inside the asset repo.
    :stackoverflow: 4
    r
    • 2
    • 3
  • p

    pablisco

    04/03/2019, 6:39 AM
    Does this seem like a good use of extension functions? Yay or nay? Any suggestions? https://twitter.com/pablisc0/status/1113129390572032000
    👍 3
    r
    g
    • 3
    • 4
  • j

    Jan

    04/03/2019, 9:53 AM
    i've always found those extensions incredibly helpful https://github.com/exozet/AndroidCore/blob/master/core/src/main/java/com/exozet/android/core/extensions/Resource%2BExtensions.kt#L49-L126
    👍 4
    s
    m
    +2
    • 5
    • 5
  • m

    monicalabbao

    04/04/2019, 5:47 AM
    Do I really have to have a
    ViewModel
    in order to extend a
    PagedListEpoxyController
    ? like so: https://github.com/airbnb/epoxy/blob/master/epoxy-pagingsample/src/main/java/com/airbnb/epoxy/pagingsample/PagingSampleActivity.kt
    :stackoverflow: 4
    :google: 4
    d
    r
    r
    • 4
    • 6
  • a

    Andy Victors

    04/04/2019, 7:40 AM
    My Kotlin multiplatform module looks like this in Android Studio: there are 4 modules (could be ok), but I cannot see the sources from commonMain. Any tricks how to beat it (except switching to IDEA 😉?)
    🙂 1
    a
    • 2
    • 2
  • g

    gsala

    04/04/2019, 11:08 AM
    Is getting references to views in an Activity like this considered a bad practice ?
    val button : Button by lazy {
        findViewById(R.id.button)
    }
    r
    s
    +4
    • 7
    • 47
  • a

    alle.iacob

    04/05/2019, 8:46 AM
    Hi, can someone recommend me a library that can execute Javascript code in android outside webview?
    g
    k
    +3
    • 6
    • 12
  • j

    Jiri Malina

    04/05/2019, 10:14 AM
    Hi, I’m still a bit confused about CoroutineScopes and CoroutineContext. I have a component which launches two coroutines 1. Coroutine which should run even if the user leaves the screen (parses a response from the server and stores the data into the db) 2. Coroutine which is tied to the UI and should be canceled as soon as Android’s ViewModel onClear method is called. I have a couple of questions a) What should I pass to the component - scope or context? b) If I create a context in the ViewModel with
    backgroundDispatcher + job
    and pass it into the component and I run GlobalScope.launch(context). Will
    job.cancel()
    cancel it?
    a
    s
    • 3
    • 3
  • h

    Heart D

    04/05/2019, 12:20 PM
    Hello guys am designing an app that uses buttons to call different people. but am failing on setting onclicklistener for all the buttons to work. i can set the onclicklistener for only on button but for many i dont know how to do it. am new in kotlin android
    :stackoverflow: 11
    n
    p
    • 3
    • 2
  • f

    febs

    04/05/2019, 1:00 PM
    Hello, I'm trying to debug my app and I have a problem: I keep stepping into the Kotlin collections file although I don't want to. The option "do not step into kotlin runtime library" is checked in the "stepping" section of the settings. I also added "kotlin.*" into the classes to exclude from stepping. Nevertheless, when I "step over" I keep getting into _Collections.kt How can I avoid that? Thanks,
    r
    • 2
    • 2
Powered by Linen
Title
f

febs

04/05/2019, 1:00 PM
Hello, I'm trying to debug my app and I have a problem: I keep stepping into the Kotlin collections file although I don't want to. The option "do not step into kotlin runtime library" is checked in the "stepping" section of the settings. I also added "kotlin.*" into the classes to exclude from stepping. Nevertheless, when I "step over" I keep getting into _Collections.kt How can I avoid that? Thanks,
r

rook

04/05/2019, 6:09 PM
I’m not sure this pattern will fix all cases, but you could add a
_*.kt
rule
Unless you’re starting any of your objects with
_
View count: 1