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

    K0NN4

    06/17/2019, 1:36 PM
    But I am getting this:``` None of the following functions can be called with the arguments supplied: @InlineOnly public inline fun print(message: Any?): Unit defined in kotlin.io @InlineOnly public inline fun print(message: Boolean): Unit defined in kotlin.io @InlineOnly public inline fun print(message: Byte): Unit defined in kotlin.io @InlineOnly public inline fun print(message: Char): Unit defined in kotlin.io @InlineOnly public inline fun print(message: CharArray): Unit defined in kotlin.io @InlineOnly public inline fun print(message: Double): Unit defined in kotlin.io @InlineOnly public inline fun print(message: Float): Unit defined in kotlin.io @InlineOnly public inline fun print(message: Int): Unit defined in kotlin.io @InlineOnly public inline fun print(message: Long): Unit defined in kotlin.io @InlineOnly public inline fun print(message: Short): Unit defined in kotlin.io
    Task :app:buildInfoGeneratorDebug```
    l
    • 2
    • 2
  • l

    Lukas Anda

    06/17/2019, 4:15 PM
    Hi I was curious, Couroutines Vs RxJava ? Which one is more suitable in your opinion ? For me it's Rx mainly because I have more experience with it, but what do you guys think ?
    c
    l
    +2
    • 5
    • 8
  • a

    Adam Hurwitz

    06/17/2019, 7:04 PM
    I'd love to know if anyone has explored the Unidirectional Data Flow for Android? I took a unique approach implementing it with LiveData + Kotlin as opposed to RxJava. A few major Kotlin benefits with this pattern are the
    Sealed class
    and the shallow
    .copy(..)
    function. I'd love any feedback on this new approach! 🙂 🤖 Medium - https://hackernoon.com/android-unidirectional-flow-with-livedata-bf24119e747 YouTube -

    https://youtu.be/Elp-Z-pQTpM▾

    😲 3
    b
    s
    • 3
    • 11
  • b

    Brian Mahecha

    06/17/2019, 9:06 PM
    Afternoon everyone! I currently have a C# Android application out in the app store. I'm looking to rewrite app in Kotlin. How hard is it to swap an app artifact out and make sure the id/purchase id's and all that match?
    d
    • 2
    • 1
  • d

    diego-gomez-olvera

    06/18/2019, 10:06 AM
    Hello! is it possible to use
    kotlin-android-extensions
    for
    @Parcelize
    but not for views?
    d
    s
    • 3
    • 12
  • t

    Tuan Kiet

    06/18/2019, 10:42 AM
    is it safe to exclude
    .kotlin_module
    files when build release apk?
    s
    g
    • 3
    • 2
  • b

    Byron Woodfork

    06/18/2019, 3:46 PM
    Anyone have any links/resources for Android XML style guides?
    g
    j
    +2
    • 5
    • 6
  • b

    bryan

    06/18/2019, 10:16 PM
    I’m just now using coroutines in Android more exclusively. I build a library that takes care of analytics for a suite of apps. The public functions on that library are
    suspend
    functions. If I want to log, say, which screen the user opened then I’ll want to call one of those
    suspend
    functions from the library. However, if I’m calling from
    onCreate
    in an
    Activity
    , what coroutine scope do I want to use? I want the analytics to get recorded and not canceled if the
    Activity
    is destroyed.
    n
    i
    • 3
    • 2
  • d

    dhananjaykulkarni19

    06/19/2019, 5:50 AM
    Dear All, I want to build an instagram like stories feature. Any help / resources will be helpful. 🙏 TIA
    g
    • 2
    • 1
  • k

    K0NN4

    06/19/2019, 2:28 PM
    Hello, how would I get "url" out of Json like this with kotlin:``` { "meta": { "status": 200 }, "response": { "hits": [ { "highlights": [], "index": "song", "type": "song", "result": { "url": "https://genius.com/Lucidious-changes-lyrics",```
    :stackoverflow: 1
    t
    m
    +3
    • 6
    • 5
  • c

    Chainchelliah

    06/19/2019, 3:47 PM
    @jw I still facing the below issue after updating kotlin version to 1.3.40. public abstract fun writeToParcel(p0: Parcel!, p1: Int): Unit defined in android.os.Parcelable. Still I need to stick with androidExtensions { * experimental = true* * }* . Please clarify.
    🙏 1
    s
    • 2
    • 2
  • y

    yogaboy

    06/20/2019, 7:44 AM
    Hi boys... any suggestions for Android Studio Git (Bitbucket) Plugin with pull-requests fnct?
    g
    r
    s
    • 4
    • 7
  • s

    Slackbot

    06/21/2019, 12:33 PM
    This message was deleted.
    r
    s
    r
    • 4
    • 3
  • b

    blakelee

    06/21/2019, 5:43 PM
    Anyone happen to know if Retrofit 2.6.0 uses Dispatchers.IO by default with coroutines?
    g
    • 2
    • 5
  • s

    Suraj Shah

    06/24/2019, 8:05 AM
    Would a
    Contract
    for deprecation be a good idea? Take
    Html.fromHtml
    for example, even though we have
    HtmlCompat
    we wont have to go and create a
    XxxCompat
    for everyone if something like this was possible. Consider this snippet:
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    Html.fromHtml(contactToDisplay, Html.FROM_HTML_MODE_LEGACY)
                } else {
                    @Suppress("DEPRECATION") // maybe we can do something to avoid this? 
                    Html.fromHtml(contactToDisplay)
                }
    If we could wrap this in a contract maybe, plus android SDKs mostly have when a particular api was deprecated, even though below a particular SDK level, it was completely fine using it. Also, looking at a bigger picture we could maybe not just use primal checks like
    implies x != null
    there could be some other annotation with retention policy of runtime or something and maybe we could do
    implies x is NotDeprecated::class.java
    or something. Just a thought.
    i
    • 2
    • 3
  • j

    Joan Colmenero

    06/24/2019, 2:55 PM
    Tried something like this
    Mockito.when(view.hideKeyboard()).then(doNothing())
    l
    r
    • 3
    • 10
  • s

    SrSouza

    06/24/2019, 6:09 PM
    Hi guys, I'm studying android + kotlin in google Udacity course and in the course say that for performance improvement we shouldn't use a lot findViewById when you can store the view in a field. My question is, AndroidX adds a way better to get views just putting the name of it and using, internally this property calls findViewById ? I should store this view too using AndroidX ?
    n
    d
    +2
    • 5
    • 5
  • t

    TheDukerChip

    06/25/2019, 11:13 AM
    I'm using this data class to store the form data
    data class FormData(
        private var _email: String = "",
        private var _password: String = "",
        private var _isAllFieldsValid: Boolean = false
    ) : BaseObservable() {
        var email: String
            @Bindable get() = _email
            set(value) {
                _email = value
                notifyPropertyChanged(BR.email)
            }
    
        var password: String
            @Bindable get() = _password
            set(value) {
                _password = value
                notifyPropertyChanged(BR.password)
            }
    
        // I want this function to be notifed for both email and password changes
        fun onValuesChanged() {
            
        }
    }
    Is there any way to achieve this rather than callback or observer?
    s
    p
    • 3
    • 2
  • a

    am414

    06/25/2019, 4:23 PM
    I wanna start to learn Rx reactive programming I know some concepts but didn't use it before 1- Could u please someone recommend me something to learn? 2- someone told me that I have to learn it in java first, is it true? 3- also in kotlin i see rxkotlin, coroutines, rxAndroid, I don't know what is preferred? thanks in advance ♥️
    k
    d
    +2
    • 5
    • 23
  • j

    Julian Bissekkou

    06/25/2019, 6:16 PM
    Did anyone play around with compose? The documentation said something about a live preview but I can‘t find any :/
    j
    r
    • 3
    • 6
  • v

    victoralissont5

    06/25/2019, 11:11 PM
    Moreover, Kotlin's concept of suspending function provides a safer and less error-prone abstraction for asynchronous operations than futures and promises. Could someone explain why this is true?
    g
    • 2
    • 4
  • t

    touge

    06/26/2019, 8:34 AM
    I have confuse when using lifecycleScope in fragment, why the fragment’s context is null inside lifecycleScope? I also asked this on stackoverflow, here is the link: https://stackoverflow.com/questions/56415530/why-the-fragments-context-null-inside-lifecyclescope
    g
    e
    • 3
    • 20
  • s

    Slackbot

    06/26/2019, 10:51 PM
    This message was deleted.
    g
    u
    +2
    • 5
    • 13
  • p

    Padawanchichi

    06/27/2019, 3:38 PM
    Lately we’ve been wrapping callback into Coroutines for libraries that specifically need callbacks to function and offer no Coroutines nor Rx connectors. The snippet we’re using to achieve that comes from kotlinlang forums, some of you may recognize it.
    suspend fun <T> awaitCallback (block: (Callback<T>) -> Unit) : T =
        suspendCancellableCoroutine { continuation ->
            block(object : Callback<T> {
                override fun onComplete(result: T) {
                    if (continuation.isActive) {
                        continuation.resume(result)
                    } else {
                        ...
                    }
                }
            })
        }
    I admit I’m not fully mastering that snippet (could be arguable to use it in our codebase) but it’s allowing us to get rid of callbacks when there’s no alternatives. We’re using it with firebase iirc. It’s working well, however we have a lot of trouble covering that particular snippet of code using Unit Tests. We’re using Mockito/Powermockito and seting up the unit test with this code :
    @Captor
    private lateinit var callbackCaptor: ArgumentCaptor<Callback<Any>>
    
    @Mock
    private lateinit var lambdaReceiver: (Callback<Any>) -> Unit
    Anybody do have tips to cover that the above method using Mockito/Powermockito ?
    e
    • 2
    • 34
  • c

    CamilleBC

    06/27/2019, 3:46 PM
    Hello! I'm wondering if anybody knows of a simple way to avoid
    data class
    duplication when using room. I have a
    data class
    from a custom library (Kotlin but NOT Android). I have an Android app that uses that library and will store some items of that
    data class
    . But as far as I can see, I don't find an easy way to create an
    entity
    from that library
    data class
    . Any ideas?
    • 1
    • 1
  • v

    veer

    06/28/2019, 7:24 AM
    Hello there, we are facing a problem with ROOM DB it says the newly added column is not found, room library version is 2.1.0, the app crashes, we have handled adding of the column in the migration, the migration seems to be successfull since the user can use other parts of the app, but when the tables where a new column is added it crashes saying, Not all users are facing this problem only 10% of users are having this problem, and mainly on Samsung s9 with Android 9 facing more. This was the old table CREATE TABLE “pfile” (“id” INTEGER PRIMARY KEY NOT NULL ,“name” VARCHAR,“lname” VARCHAR,“rlhip” VARCHAR,“sex” VARCHAR,“wk” VARCHAR,“un” VARCHAR,“fun” VARCHAR,“pn” BOOL NOT NULL DEFAULT (1) ,“dd” DOUBLE,“add” DOUBLE,“ph” BLOB,“hk” BOOL,“th” VARCHAR,“fun” VARCHAR, “swk” VARCHAR) Changed to the below( data type of some columns changed and tun column is added) “CREATE TABLE pfile_new (id INTEGER PRIMARY KEY NOT NULL ,name TEXT, lname TEXT, ” + “rlhip TEXT, sex TEXT, wk TEXT, un TEXT, lun TEXT, ” + “pn INTEGER NOT NULL, ” + “dd REAL, pdd REAL, ph BLOB, hk INTEGER, th TEXT, fun TEXT, swk TEXT, tun TEXT)” This is the code in the migrate function database.execSQL(“”CREATE TABLE pfile_new (id INTEGER PRIMARY KEY NOT NULL ,name TEXT, lname TEXT, ” + “rlhip TEXT, sex TEXT, wk TEXT, un TEXT, lun TEXT, ” + “pn INTEGER NOT NULL, ” + “dd REAL, pdd REAL, ph BLOB, hk INTEGER, th TEXT, fun TEXT, swk TEXT, tun TEXT)” ) database.execSQL(“INSERT INTO pfile_new (id, name, lname, rlhip, sex, wk,un,lun,on,dd,pdd,ph,hk,th,fun,swk) ” + “SELECT id, name, name, rlhip, sex, wk,lun, pn,dd,pdd,ph,hk,theme, fun +swk ” + “FROM pfile”) database.execSQL(“UPDATE profile_new set tun = ‘$tun’“) database.execSQL(“DROP TABLE pfile”) database.execSQL(“ALTER TABLE pfile_new RENAME TO pfile”) This is the method in the DAO @Query(“SELECT * FROM pfile”) fun getData(): List<Pfile> Following is the error we see, java.lang.IllegalArgumentException column ‘tun’ does not exist. Available columns: [id, name, lname, rlhip, sex, wk, un, lun, pn, dd, pdd, photo, hk, th, fun, swk] com.example.database.dao.UserDao_Impl.getData
    r
    c
    • 3
    • 7
  • j

    jecarr33

    06/28/2019, 8:42 AM
    Hello, I was wondering if anybody could give me any guidance for adding recyclerview to my project. I haven't done any android development for a very long time. It used to be in the support library if I remember correctly but when I read the docs at android developer, it says to use the new
    androidx
    libraries. I can't seem to find the version number of the latest androidx recycler view. When I search online I see a lot of old posts which direct you back to the support library. Can anybody please help me to find what I'm supposed to put in the
    implementation
    portion of the gradle build???
    :google: 2
    :stackoverflow: 2
    r
    k
    • 3
    • 2
  • f

    Fredrik Larsen

    06/28/2019, 2:34 PM
    Hi, I have a callback when you click cancel in an AlertDialog. I'm trying to figure out why the exception is not caught in this case. Can anyone shed some light on it? https://gist.github.com/frel/38aaa8a05790a401dd45317c527b85eb I assume it's because of the stack trace, but I'm not sure what the alternative would be. This is the simplest version I could think of where I'm able to reproduce the issue. I'm actually trying to make an rx stream error, but instead the app crashes.
    c
    d
    • 3
    • 9
  • g

    goku

    07/01/2019, 1:47 AM
    A while ago I’ve read somewhere that
    View Holder
    shouldn’t be an
    inner class
    . I don’t remember where I read it, but I don’t see any problem with making
    ViewHolder
    an
    inner class
    . Any thoughts on this?
    g
    • 2
    • 2
  • s

    Shan

    07/01/2019, 2:45 AM
    Question: I read that Android's Room uses its own Dispatcher to run all query functions. 1. Is that true? and 2. If so, what is the correct way to run suspend fun queries from the view model? What dispatcher should I launch the coroutine with which runs the query?
    g
    • 2
    • 12
Powered by Linen
Title
s

Shan

07/01/2019, 2:45 AM
Question: I read that Android's Room uses its own Dispatcher to run all query functions. 1. Is that true? and 2. If so, what is the correct way to run suspend fun queries from the view model? What dispatcher should I launch the coroutine with which runs the query?
g

gildor

07/01/2019, 3:11 AM
just run them, no need to worry about particular dispatcher, because it will run the query on own thread pool and return result to your own dispatcher, so use any dispatcher which is required for your code, not for room, usually just use default dispatcher of CoroutineScope
s

Shan

07/01/2019, 3:12 AM
ah, gotcha! thanks!
g

gildor

07/01/2019, 3:15 AM
in general, correct implementation of any suspend function should never require any specific dispatcher and never should be blocking, everything else should be considered as bug of implementation of this suspend function
s

Shan

07/01/2019, 3:21 AM
Getting this error when trying to just launch it without a specific dispatcher from my ViewModel's scope :
java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
😞
Well, I am 98.9% sure it's because my ViewModel's context is
viewModelScope.coroutineContext
which is bound to
Dispatchers.Main
But now I'm not entirely sure of the correct way to handle this
g

gildor

07/01/2019, 3:41 AM
is it happening when you launch suspend function from room?
or blocking one?
s

Shan

07/01/2019, 3:43 AM
when I call
viewModel.launch { 
    val destination = destinationsDao.getLastActive(true)
}
from my fragment. the query is:
@Query("SELECT * FROM destinations WHERE last_active = :lastActive")
    fun getLastActive(lastActive: Boolean) : Destination?
d'oh, i had removed my suspend from my query function, popping that back in fixed it
g

gildor

07/01/2019, 3:46 AM
But this is not a suspend function
yes, exactly
View count: 2