https://kotlinlang.org logo
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
  • t

    Tony

    04/15/2020, 3:22 PM
    Hello, I have a question about data classes and types. I have an API where it returns a field called text. Text can either have the type of String or type List<Object>. How would I handle creating a data class for this?
    c
    • 2
    • 7
  • c

    Cody Engel

    04/16/2020, 5:15 PM
    For
    TypedArray
    in Android, I added the following extension function to handling parsing the values:
    fun TypedArray.parseStyledAttributes(parse: (typedArray: TypedArray) -> Unit) {
        try {
            parse(this)
        } finally {
            recycle()
        }
    }
    However the call-site still gives a lint warning "This typed array should be recycled after use with #recycle()". Is there anything I could do besides adding
    @SuppressLint("Recycle")
    everywhere?
    a
    j
    • 3
    • 7
  • i

    iex

    04/16/2020, 5:42 PM
    ah, I found the solution: https://medium.com/the-kotlin-chronicle/why-you-should-use-class-delegation-in-kotlin-fb0a3ebf151e
    c
    • 2
    • 13
  • a

    Ahmed Ibrahim

    04/16/2020, 6:45 PM
    Does anyone know where can I find the official documentation for the Android Kotlin extensions? I'm trying to enable
    @Parcelize
    support, but when I look it up at Google I see a bunch of medium articles, and the link that leads to kotlinlang.org pointing to this link [1], which doesn't have a mention for it. Even Jake Wharton's tweet[2] mentioning that it became stable redirects to [1]. {1] https://kotlinlang.org/docs/reference/android-overview.html [2] https://twitter.com/JakeWharton/status/1116424059162644480
    r
    b
    • 3
    • 3
  • d

    Deepti M

    04/16/2020, 10:09 PM
    Hi! I need context in many classes other than activity or fragment. I am passing it as a method parameter, wherever required. But I feel, as per DI framework, I should make app-context available at all places. For doing the same, I found this reference. While along with this, also found one discussion, which says my old implementation is correct. I AM CONFUSED 😞 Can anybody help? https://gist.github.com/paraya3636/bf8108a75eb49323e56c0c90dd0747e0 https://discuss.kotlinlang.org/t/access-application-context-in-companion-object-in-kotlin/11054
    c
    p
    +2
    • 5
    • 40
  • d

    Daniella Paiva

    04/17/2020, 2:07 PM
    Good morning, guys, how are you? We recently implemented the option to share a screenshot of the application. We have uploaded this update and we are having the following problem with the native Media path. Has anyone ever experienced this ?
    c
    c
    p
    • 4
    • 12
  • l

    Lilly

    04/17/2020, 2:57 PM
    Stupid question, but is it possible to compile against Java 12 (Java 11 is working):
    compileOptions {
            sourceCompatibility = JavaVersion.VERSION_12
            targetCompatibility = JavaVersion.VERSION_12
        }
    
        kotlinOptions {
            jvmTarget = "12"
        }
    I get Unsupported class file version: 56. AS: 4.1 C5 Gradle: 6.3 Kotlin: 1.3.72 JDK: 14.0.1 When I'm searching for "android java 12/13 support" I find sources that claim gradle/kotlin/IntelliJ is supporting both so did I miss something or is it just not supported yet?
    m
    j
    • 3
    • 19
  • k

    kartoffelsup

    04/17/2020, 7:32 PM
    Hi, I recently get these exceptions (using coroutines and okhttp):
    E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
        Process: io.github.kartoffelsup.nuntius, PID: 2334
        java.lang.NoSuchMethodError: No static method post$default(Lio/github/kartoffelsup/nuntius/client/NuntiusApiService;Ljava/lang/String;Ljava/lang/Object;Lkotlinx/serialization/KSerializer;Lkotlinx/serialization/KSerializer;Ljava/lang/String;ILjava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; in class Lio/github/kartoffelsup/nuntius/client/NuntiusApiService; or its super classes (declaration of 'io.github.kartoffelsup.nuntius.client.NuntiusApiService' appears in /data/app/io.github.kartoffelsup.nuntius-1/base.apk:classes3.dex)
            at io.github.kartoffelsup.nuntius.data.user.UserService.login(UserService.kt:27)
            at io.github.kartoffelsup.nuntius.ui.user.UserLoginScreenKt$UserLoginScreen$formState$1$1.invokeSuspend(UserLoginScreen.kt:94)
            at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
            at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
            at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
            at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
            at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
            at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
    I'm guessing I need a proguard rule or something? I added this:
    -keepclassmembers class io.github.kartoffelsup.nuntius.client.NuntiusApiService {
        *;
    }
    but that didn't help unfortunately. Code is here: https://github.com/kartoffelsup/nuntius-app/blob/master/app/src/main/java/io/github/kartoffelsup/nuntius/ui/user/UserLoginScreen.kt#L94 https://github.com/kartoffelsup/nuntius/blob/master/client/src/commonMain/kotlin/io/github/kartoffelsup/nuntius/client/NuntiusApiService.kt#L11-L17 Any pointers? Thanks!
    • 1
    • 1
  • v

    viralshah

    04/18/2020, 2:36 AM
    Whats the best way to manipulate a Kotlin map to get this result
    val k = "total"
    
    
    [{"id": "123", "total": "56.00"}, {"id": "456", "total": "55.00"}]
    
    to
    
    map id -> k 
    
    {"123": "56.00", "456": "55.00"}
    j
    d
    • 3
    • 3
  • w

    wadva

    04/18/2020, 11:22 AM
    i tried using kotlin version 1.4-M1 in android studio and i have been getting this error
    Gradle sync failed: Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M1.
    i
    • 2
    • 2
  • j

    jme

    04/20/2020, 12:23 AM
    As a Friday project I've prototyped a Gradle Plugin which generates a typed equivalent to
    R.java
    using Kotlin's experimental Inline Classes, giving us better compile-time type safety over resource referencing. For example:
    R.color.red
    is of type
    Int
    , whereas
    K.color.red
    is of type
    ColorRes
    . Is this something that people would be interested in? There's more work to be done to make it production-ready, and it feels like this should be somewhere more central (like AGP), but you can find more examples and the code in this Github repo
    e
    j
    • 3
    • 7
  • d

    dewildte

    04/20/2020, 2:23 PM
    Does anyone know why
    System.console
    returns null?
    c
    • 2
    • 2
  • c

    codeslubber

    04/20/2020, 4:32 PM
    Is this code lab on testing still valid? (state of the art?) I cloned it and it seemed like it has not been touched in a long time.. been reading about AndroidX testing, but as I look at code I still see deprecated stuff.. ? https://codelabs.developers.google.com/codelabs/advanced-android-kotlin-training-testing-basics/index.html#0
    a
    m
    p
    • 4
    • 28
  • c

    Colton Idle

    04/20/2020, 4:41 PM
    I noticed that after adding kotlin to my android project my build output is littered with this. (Both locally and CI)
    > Task :app:compilePaidDebugKotlin
    w: /bitrise/src/app/src/rollertoaster/myview/HealthView.kt: (66, 46): No cast needed
    w: /bitrise/src/app/src/rollertoaster/myview/HealthView.kt: (97, 44): Parameter 'dialog' is never used, could be renamed to _
    w: /bitrise/src/app/src/rollertoaster/myview/HealthView.kt: (174, 40): Parameter 'dialog' is never used, could be renamed to _
    w: /bitrise/src/app/src/rollertoaster/myview/HealthView.kt: (416, 21): The expression is unused
    w: /bitrise/src/app/src/rollertoaster/myapp/HealthInitializer.kt: (33, 24): Parameter 'context' is never used
    w: /bitrise/src/app/src/rollertoaster/myapp/MyDialog.kt: (48, 27): Condition 'response.yours == null' is always 'false'
    w: /bitrise/src/app/src/rollertoaster/myapp/MyDialog.kt: (54, 13): Condition 'actions == null' is always 'false'
    w: /bitrise/src/app/src/rollertoaster/myapp/MyDialog.kt: (55, 57): Parameter 'w' is never used, could be renamed to _
    ...
    A lot of these warning a so tiny, is there an easy way to just fix all of them, or just prevent them? Not sure why they even show up honestly.
    z
    • 2
    • 2
  • i

    iex

    04/21/2020, 7:50 AM
    can I find a fragment in the backstack with its id? This:
    private fun NavHostFragment.hasDestinationInBackstack(destinationId: Int): Boolean {
        for (index in 0 until childFragmentManager.backStackEntryCount) {
            if (childFragmentManager.getBackStackEntryAt(index).id == destinationId) {
                return true
            }
        }
        return false
    }
    doesn't work, because
    id
    returns 0, 1, 2... with tag maybe?
    a
    • 2
    • 2
  • e

    emmano

    04/21/2020, 1:20 PM
    Quick question, if you are using Android’s Navigation component, how are you making sure button clicks are debounced so you do not get this type of
    Exception
    ?
    java.lang.IllegalArgumentException navigation destination action_loadingFragment_to_fragmentHome is unknown to this NavController
    w
    d
    • 3
    • 4
  • s

    Santiago Oroz17

    04/21/2020, 7:16 PM
    Hi everyone I have a problem whit DaggerAppCompatActivity and Binding, They are not compatible? I have this error :
    Caused by: java.lang.IllegalArgumentException: View is not a binding layout. Tag: layout/activity_movie_0
    but only with DaggerAppCompatActivity
    d
    • 2
    • 4
  • j

    Joao Birk

    04/21/2020, 8:40 PM
    Hi, does anyone know a good
    layout formatter
    like
    ktlint
    ?
    v
    j
    • 3
    • 7
  • d

    Derrick Wadek

    04/22/2020, 9:17 AM
    I have a recyclerview that is not showing any items. Am using a listadapter.
    e
    • 2
    • 2
  • d

    Derrick Wadek

    04/22/2020, 9:19 AM
    class MainActivity : AppCompatActivity(), KodeinAware {
    
        override val kodein by kodein()
        private var notesAdapter: NotesAdapter ?= null
        private var mLayout : LinearLayoutManager ?= null
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
    
            ft_btn.setOnClickListener {
                val intent = Intent(this, AddNoteActivity::class.java)
                startActivity(intent)
            }
    
            initRecyclerview()
    
            val db = NoteRoomDatabase(this)
            val repo = NotesRepository(db)
            val factory = NotesViewModelFactory(repo)
    
            val notesViewModel : NotesViewModel = ViewModelProvider(this, factory).get(NotesViewModel::class.java)
            notesViewModel.getAllNotesFromDB().observe(this, Observer {
                notesAdapter?.submitList(it)
            })
        }
    
        private fun initRecyclerview(){
            recyclerView.setHasFixedSize(true)
            mLayout = LinearLayoutManager(this)
            recyclerView.layoutManager = mLayout
            recyclerView.adapter = notesAdapter
        }
    }
    k
    e
    +2
    • 5
    • 9
  • j

    Jitesh Dedhiya

    04/22/2020, 1:39 PM
    There is a Kotlin Ultimate Challenge for Kotlin Enthusiasts - Registrations - https://bit.ly/3cB9StM. Join slack #kotlinultimatechallenge
    d
    • 2
    • 5
  • b

    Bacho Kurtanidze

    04/22/2020, 3:40 PM
    hi Im new to view binding and trying it out in my new project. I know that it meant to be very simple and light-weight library and thats why it doesnt have many functions, but what if we could write or extend functional of generated view binding class, so for example, instead of 
    binding.registerButton.setOnClickListener{}
    we would be able to write
    binding.onRegisterButtonClick{}
    . does it make any sense? or am I talking about data binding right now?
    a
    • 2
    • 1
  • s

    Santiago Oroz17

    04/22/2020, 7:18 PM
    Hello everyone. I have to make 3 apps but they are all very equal, practically it shares 90% of its code. Which is to recommend working with multi apps and combining it with a common module, or making an app and managing it with flavors. Each app must be in the play store and have its configuration of json services from firebase
    a
    h
    • 3
    • 3
  • l

    lawlorslaw

    04/23/2020, 1:10 AM
    so if you had the list a b c d e then i want it to be a / b / c / d / e
    d
    • 2
    • 3
  • k

    Keith

    04/23/2020, 4:27 AM
    This is when I’m running the code in an emulator.
    d
    • 2
    • 1
  • b

    Bilal Sohail

    04/23/2020, 6:54 AM
    Everyday, I'm Strugglin'! I set out to make an Android (Kotlin) app. The app is supposed to be a Music Pre-Production Based, Social Engagement Platform. It encapsulates functionalities like Music Player, User Preferences,Artist Portfolios, Messenger etc built into it. What baffles me right now, is figuring out the frameworks/available APIs to create a backend data model for this app. HELP PLEASE!
    r
    • 2
    • 3
  • m

    Mohamed Ibrahim

    04/23/2020, 7:04 AM
    How to use
    @Parcelize
    with a class has a generic type like
    List<T>?
    d
    • 2
    • 1
  • r

    Răzvan Roșu

    04/23/2020, 7:12 AM
    Hi, I'm struggling with a corporate API service that requires authentication through OAuth 2. When the application is started for the first time, the user clicks the button Login and the activity launches the default browser with the login page. As soon as the client enters the right credentials, the browser, through a callback procedure passes the data to the same LoginActivity needed to obtain the access token and complete the procedure. The whole procedure on my Google Pixel works well as it does on the AVD, but on different phone brands like Samsung the browser does not always invoke the application. On other brands like Meizu it never works, even if Chrome is installed. I was wondering if it was another way to make the OAuth authentication without relying on an external browser, but after some research I found out that using the WebView on native applications is insecure. And some users find the opening of the external browser a little bit confusing. Here are the intent filters that I use in case someone is curios:
    <activity                android:name=".ui.login.LoginActivity"                android:theme="@style/LoginTheme">
    <`intent-filter> <action android:name="android.intent.action.VIEW" />` <`category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" />` <`data android:host="service-name" android:path="/oauth-callback" android:scheme="http" /> </intent-filter>` </`activity>` Thanks in advance!
    d
    • 2
    • 5
  • a

    Ali

    04/23/2020, 9:49 AM
    What's the best way to handle this?
    response.some1?.let { some1 -> response.some2?.let { some2 -> some1 + some2 } }
    h
    l
    • 3
    • 2
  • l

    Lilly

    04/23/2020, 8:35 PM
    Hi, can someone give me a hint how to arrange 2 columns in compose. One vertical center and the other one bottom center. I tried every combination of column, box but one column is always put into the other one. To be more concrete: I just want to realize a login screen. 2 TextFields vertically center and a version Text at the bottom center.
    m
    • 2
    • 1
Powered by Linen
Title
l

Lilly

04/23/2020, 8:35 PM
Hi, can someone give me a hint how to arrange 2 columns in compose. One vertical center and the other one bottom center. I tried every combination of column, box but one column is always put into the other one. To be more concrete: I just want to realize a login screen. 2 TextFields vertically center and a version Text at the bottom center.
m

Mark Murphy

04/23/2020, 10:49 PM
you may have better luck in the #compose channel
View count: 5