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

    Slackbot

    01/20/2021, 7:25 AM
    This message was deleted.
    g
    a
    • 3
    • 8
  • p

    paulex

    01/20/2021, 12:18 PM
    Please I need some help with MotionLayout I have tried a lot but it’s seems futile. I handle my recycler view visibility programmatically , it’s tied to loading from network and all that. However, when OnSwipe I have an header I’m trying to animate. I have added visibilityMode and set it to ignore on both start and end. But for some reasons it still doesn’t display. If I set the layout properties on the scene it displays but then the animation doesn’t work, more like it does it very fast regardless of the duration
    :stackoverflow: 1
    a
    • 2
    • 3
  • v

    Vladimir Vasic

    01/20/2021, 12:53 PM
    Hello, I'm having a problem with polymorphic serialization with discriminator in request. When I try to serialize object my discriminator is not being added. I'm using ktor 1.5 and kotlinx serialization I'm gonna write mock classes to mimic my classes here:
    @Polymorphic
    @Serializable
    abstract class Base {
    
        @SerialName("property_1")
        abstract val property1: String
    
        @SerialName("property_2")
        abstract val property2: String
    }
    
    private const val DISCRIMINATORA = "5"
    
    @Serializable
    @SerialName(DISCRIMINATORA)
    data class A(
    
    @SerialName("property_1")
        override val property1: String,
    
    @SerialName("property_2")
        override val property2: String,
    
    @SerialName("propertyA")
        val propertyA: String,
    
    ) : Base()
    
    private const val DISCRIMINATORB = "4"
    
    @Serializable
    @SerialName(DISCRIMINATORB)
    data class B(
    
    @SerialName("property_1")
        override val property1: String,
    
    @SerialName("property_2")
        override val property2: String,
    
    @SerialName("propertyB")
        val propertyB: String,
    
    ) : Base()
    My koin definition is
    single {
        APIClient(baseUrl, get())
    }
    
    val polymorphicBaseRequestModule = SerializersModule {
        polymorphic(Any::class) {
            subclass(A::class)
            subclass(B::class)
        }
        polymorphic(Base::class) {
            subclass(A::class)
            subclass(B::class)
        }
    }
    
    single {
        HttpClient(OkHttp) {
            install(JsonFeature) {
                serializer = KotlinxSerializer(kotlinx.serialization.json.Json {
                    isLenient = true
                    ignoreUnknownKeys = true
                    classDiscriminator = "hello"
                    serializersModule =  polymorphicBaseRequestModule
                })
            }
    }
    My Request class is
    abstract class APIRequest<ReturnType : Any>(
        open val httpMethod: APIHTTPMethod = APIHTTPMethod.Get,
        open val contentType: String? = null,
        open val resourcePath: String = "/",
        open val urlParameters: HashMap<String, Any?>? = null,
        @Polymorphic
        open val httpBody: Any? = null
    )
    My API client is
    suspend inline fun <reified ReturnType : Any> send(apiRequest: APIRequest<ReturnType>): Result<ReturnType> {
        val builder = HttpRequestBuilder()
        builder.url.protocol = URLProtocol.HTTP
    
        builder.url.host = baseUrl
        builder.url.encodedPath = apiRequest.resourcePath
    
        builder.method = HttpMethod.parse(apiRequest.httpMethod.value)
    
        // Add headers
        apiRequest.contentType?.let {
            builder.headers.append("Content-Type", it)
        }
    
        // Add request body
        apiRequest.httpBody?.let { httpBody ->
            builder.body = httpBody
        }
    
        Sentry.addBreadcrumb("Resource path: " + apiRequest.resourcePath)
    
        return withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
            try {
                Result.success(client.request<ReturnType>(builder))
            }catch(e) {
                Log.d("error", e.response.content)
            }
    }
    What am I doing wrong?
    j
    • 2
    • 2
  • a

    Andrew Ebling

    01/20/2021, 4:33 PM
    when I try and create a SparseArray, like this:
    var array = SparseArray<ByteArray>(1)
    ...array ends up being empty (it shows as
    “null”
    in the debugger, and if I do this:
    array.setValueAt(0, byteArrayOf(byte)
    val value = array.get(0)
    ...then
    value
    is
    null.
    m
    g
    • 3
    • 15
  • s

    Sulav Timsina

    01/22/2021, 3:44 AM
    Hello all,is there any channel where I can ask Google ML textRecognition related question?
    • 1
    • 1
  • j

    Jason Ankers

    01/22/2021, 6:32 AM
    Anyone have any experience with overlapping elements in jetpack compose? i.e. a button with a badge icon
    k
    m
    • 3
    • 4
  • s

    Shawn Tucker

    01/22/2021, 8:30 AM
    https://jakewharton.com/a-jetpack-compose-by-any-other-name/ Anyone have more information about this? this is very interesting and I cant find more sources about the topic
    z
    e
    • 3
    • 4
  • i

    Imany

    01/22/2021, 8:41 AM
    hey guys I would be grateful if anybody could help me. I added gradle plugins in
    settings.gradle.kts
    like this:
    pluginManagement {
        repositories {
            gradlePluginPortal()
            google()
        }
    plugins {
            id(GradlePluginId.GRADLE_PLUGIN) version GradlePluginsVersion.GRADLE_PLUGIN
        }
    }
    that
    GradlePluginId
    and
    GradlePluginVersion
    are Kotlin objects, but the problem is they don't resolve with just this message: _*Unresolved reference: GradlePluginId Unresolved reference: GradlePluginVersion*_ however I can go to declaration and back to usage through the IDE. my project settings:
    implementation("com.android.tools.build:gradle:4.1.1")
    distributionUrl=<https://services.gradle.org/distributions/gradle-6.5-bin.zip|https://services.gradle.org/distributions/gradle-6.5-bin.zip>
    thank you.
    v
    h
    • 3
    • 13
  • j

    Junior leoncio

    01/22/2021, 4:48 PM
    hello guys, i'm creating a quiz app, i'm having trouble translating the questions i get from the open trivia database to my app, i want to translate from english to portuguese! Can someone help me?
    v
    • 2
    • 2
  • r

    Remy Benza

    01/23/2021, 3:50 PM
    Im using an NotificationListenerService for snoozing certain notifications on condition X by calling snoozeNotification(id, duration). When condition X changes during the snooze periode, how do you 'unsnooze' such a notification?
    f
    • 2
    • 13
  • t

    theimpulson

    01/23/2021, 4:38 PM
    Hey guys! So, I have been trying out Navigation Components. Created an activity with 2 fragments. A goes to B on button press and B has a button to go back to A by destroying current fragment. Now the issue is on this B to A fragment. If I use
    binding.button2.setOnClickListener {
                activity?.supportFragmentManager?.popBackStack()
            }
    On going back to A, if I use A to B button again, app will crash with this message:
    java.lang.IllegalArgumentException: navigation destination dev.theimpulson.myapplication:id/action_firstFragment_to_secondFragment is unknown to this NavController
    However, if I use this in B to A button:
    binding.button2.setOnClickListener {
                activity?.onBackPressed()
            }
    App doesn't crashes anymore. Any ideas why?
    r
    • 2
    • 3
  • d

    dimsuz

    01/25/2021, 12:08 PM
    Hi! I have a custom parceler
    class StringSrcParceler : Parceler<StringSrc?>
    Which I use like this:
    @Parcelize
    @TypeParceler<StringSrc?, StringSrcParceler>
    data class PermissionRequestFlowParams(
      val allowPostpone: Boolean,
      val forbidDismissWithMessage: StringSrc?,
    ) : Parcelable
    At runtime this gives me an exception:
    java.lang.NoSuchFieldError: No static field INSTANCE of type Lru/kode/base/ui/core/resources
    /StringSrcParceler; in class Lru/kode/base/ui/core/resources/StringSrcParceler
    Full: https://pastebin.com/NYBEcgE1 What am I doing wrong?
    y
    • 2
    • 2
  • e

    Eirik Vale Aase

    01/25/2021, 5:48 PM
    Hi all. I’m no Android dude, but debugging an Android issue that requires me to open a webview and input my credentials. Problem is, my external keyboard is not usable from within the webview. Works fine in the app itself (outside of the webview). Anyone having similar experiences and a possible solution?
    :stackoverflow: 1
    o
    • 2
    • 2
  • s

    sbeve

    01/26/2021, 9:23 AM
    what is this even for it everyone keeps getting told to go to stack overflow?
    d
    o
    k
    • 4
    • 8
  • j

    Jrichards1408

    01/26/2021, 8:57 PM
    Hi, I have created a android library project that uses kotlin dsl for gradle and android studio doesn't identify any module or anything from that project. I can't use basic things like finding declarations for classes or auto add imports and auto correct variable types. I may as well just open this project in notepad...
    m
    m
    • 3
    • 3
  • f

    FunkyMuse

    01/26/2021, 11:20 PM
    Anyone else suffering from https://issuetracker.google.com/issues/176138645 when using navigation component, any workarounds?
    i
    • 2
    • 3
  • t

    Tony Kazanjian

    01/27/2021, 8:34 PM
    Hello! I'm wondering if anyone with some experience with Koin could elaborate on the differences between the AndroidX package
    org.koin:koin-androidx-viewmodel:$koin_version
    versus just the basic
    org.koin:koin-android-viewmodel:$koin_version
    . I have been using the latter with ViewModels from the AndroidX lifecycle package and everything is working just fine. What would I need the AndroidX Koin dependency for?
    a
    • 2
    • 2
  • b

    Big Chungus

    01/28/2021, 11:05 AM
    Hi guys, does anyone have an example gradle config of MPP library including android target?
    y
    c
    • 3
    • 15
  • d

    deviant

    01/28/2021, 1:20 PM
    is it a good idea to wrap Activity Result api into coroutines? so instead of
    val getContent = registerForActivityResult(GetContent()) { uri: Uri? ->
        // Handle the returned Uri
    }
    getContent.launch("image/*")
    we could use something like
    val getContent = registerForActivityResult(GetContent(), suspendableContract)
    val result = getContent.launchSuspendable("image/*")
    f
    o
    i
    • 4
    • 9
  • d

    darkmoon_uk

    01/29/2021, 6:51 AM
    Looks like there is a bug in
    com.android.tools.build:gradle:7.0.0-alpha05
    - switching to this version from
    alpha04
    on my project produces the error
    lateinit property variantName has not been initialized
    . I'm running a 'standard' Kotlin Multiplatform / Mobile gradle setup.
    Gradle Plugin Alpha 05 bug stacktrace
    • 1
    • 1
  • j

    Jawid

    01/29/2021, 7:57 AM
    Hello everyone, I started working to create a Kotlin Multiplatform project. But I am facing a problem in integrating ViewModel in the project. I want to use moko-mvvm library if I use the current version (
    0.9.1
    ) it is not being imported in the shared module. Instead, if I change the version to
    0.6.0
    I can import it but I get this error
    Cannot access 'dev.icerock.moko.mvvm.viewmodel.ViewModel' which is a supertype of 'com.example.vmdemo.shared.GreetingViewModel'. Check your module classpath for missing or conflicting dependencies
    . I really appreciated it if someone could help me to solve this issue, thanks in advance.
    • 1
    • 1
  • h

    Hannan Shaikh

    01/29/2021, 9:44 AM
    Is KMM is same as flutter like create two application with single code or iOS part has to be done in swift using Xcode
    t
    • 2
    • 1
  • d

    darkmoon_uk

    01/29/2021, 1:43 PM
    ⚠️ Characterised a major bug with Android Gradle Plugin 
    7.0.0-alpha05
     , here: https://issuetracker.google.com/issues/178715706 Please consider voting for this issue to encourage a hotfix; thanks to @Sean Keane and @magnumrocha for the investigation.
    👍 2
    j
    m
    s
    • 4
    • 15
  • u

    ursus

    01/31/2021, 7:22 AM
    Does anyone know where is AGP version mapping to build tools version? I have a CI docker image with 30.0.2 build tools, and the latest stable AGP 4.1.2 only uses 29.x.y.
    a
    a
    • 3
    • 8
  • d

    Dhanya S Pillai

    02/01/2021, 9:34 AM
    Does anyone know when the jetpack compose gonna release the stable version?
    🇳🇴 5
    m
    a
    k
    • 4
    • 8
  • m

    murdock

    02/01/2021, 9:46 AM
    For anyone using In app Updates -> Is update priority working for you?
    m
    d
    • 3
    • 7
  • e

    Ellen Spertus

    02/01/2021, 10:07 PM
    I'm working through a tutorial that includes:
    rollButton.text = "Let's roll!"
            rollButton.setOnClickListener {
                Toast.makeText(this, "button clicked", Toast.LENGTH_SHORT).show()
            }
    I know the first line would be:
    rollButton.setText("Let's roll!");
    in Java. Why doesn't the next statement become the following in Kotlin:
    rollButton.onClickListener = ...;
    i
    • 2
    • 2
  • a

    Aness Iqbal

    02/02/2021, 7:25 AM
    Using one linear recyclerview, when I update the list data lets say from meters to centimeters and calling notifyDataSetChange() on adapter afterwards, it changes/shuffles the position of items(edittexts inputs for numbers) in recyclerview. How can I prevent the list from shuffling and retaining the same position for converted items? Is Diffutill recommended for this to work?
    :stackoverflow: 2
    u
    d
    a
    • 4
    • 5
  • d

    D Tam

    02/02/2021, 9:17 AM
    Hi all, does anyone know a good tutorial that explains how a view can be created programmatically. I have managed to create a view (EditText) however, I cannot set the layout_height or layout_width to anything other than MATCH_PARENT or WRAP_CONTENT. Also, I would like to add a scrollbar with minLines and maxLines. However, none of them appears to work even though they work in the XML resource file.
    :stackoverflow: 4
    a
    • 2
    • 4
  • s

    Slackbot

    02/02/2021, 1:35 PM
    This message was deleted.
    z
    s
    • 3
    • 2
Powered by Linen
Title
s

Slackbot

02/02/2021, 1:35 PM
This message was deleted.
z

Zach Klippenstein (he/him) [MOD]

02/02/2021, 1:51 PM
Not an Android question, might want to discuss in #getting-started. But specifically regarding operator overloading, check out the docs: https://kotlinlang.org/docs/reference/operator-overloading.html
s

Sachin Rana

02/02/2021, 2:09 PM
Thanks changed.
View count: 5