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

    AmrJyniat

    11/23/2021, 8:36 AM
    Hi there, can I make a default general condition applied automatically on all queries related to a specific table(Entity) in Room? eg: I have a table named tasks and there is a hidden property for each task either 0 or 1, so I want all queries getting the tasks that aren't hidden except to explicitly query the tasks that are hidden.
    :not-kotlin: 1
    e
    1 reply · 2 participants
  • z

    zain

    11/23/2021, 12:45 PM
    https://stackoverflow.com/questions/70081160/how-to-join-three-lists-into-a-single-object
    e
    1 reply · 2 participants
  • k

    Katarzyna

    11/24/2021, 8:48 AM
    In this article, Begüm Yazıcı will try to explain what are Unit tests, why should we write them, and how to write them. "It has never been easier to understand how to write Unit Tests on Android — Part 1" 👇 https://blog.kotlin-academy.com/it-has-never-been-easier-to-understand-how-to-write-unit-tests-on-android-part-1-5ed1e5d8112b
    ❤️ 1
    🙌 1
    j
    1 reply · 2 participants
  • v

    Vivek Modi

    11/24/2021, 4:45 PM
    Hey Can we eliminate characters from string *For exampl*e
    val string = "000010"
    or
    val string = "010"
    to get only
    10
    e
    v
    4 replies · 3 participants
  • m

    Mehdi Haghgoo

    11/24/2021, 4:58 PM
    Does anyone else have problems with kapt? I have applied it as plugin, but Android Studio does not find it. I'm following step three of this codelab. https://developer.android.com/codelabs/android-room-with-a-view-kotlin#3
    🇳🇴 1
    3 replies · 1 participant
  • r

    Rajput Art Studio

    11/24/2021, 5:57 PM
    Hello friends Anyone know any free video player in android like youtube with all features
    :not-kotlin: 5
    m
    m
    5 replies · 3 participants
  • r

    Richa

    11/25/2021, 5:53 AM
    Hello @all Retrofit with 443 PORT I am parsing data using Retrofit. As I used to give BASE URL and 443 PORT to Retrofit Request, BASE URL NOT WORKING WITH 443. I want to use URL like :  http://xxx.xxx.xx.xxx:443/ Is there any suggestion how do I set my BASE URL WITH 443 PORT?
    :not-kotlin: 3
    u
    c
    4 replies · 3 participants
  • n

    Nemanja Scepanovic

    11/25/2021, 10:38 AM
    Hi guys! I have one peculiar problem which I am not sure how to handle. The issue is the following, I’ve defined a value class (lets call it Query which wraps a String primitive type). I am using DataStore preferences in which I store/retrieve the string value by wrapping/unwrapping the value to Query value class accordingly. The issue I am receiving is when I subscribe to the Flow object I get
    java.lang.ClassCastException: java.lang.String cannot be cast to Query
    and I am completely puzzled to why is that? I get that value classes are “deconstructed” to the primitive type in runtime, but why am I then allowed to use them like this then? Thanks!
    r
    3 replies · 2 participants
  • v

    Vivek Modi

    11/25/2021, 12:38 PM
    Hey Everyone can someone explain me what is the d/w these two
    4 replies · 1 participant
  • a

    Aidan Low

    11/25/2021, 5:06 PM
    Meta-question for mods: Have we ever considered renaming this channel “android-kotlin” or something like that to cut down on the :not-kotlin: questions?
    v
    e
    4 replies · 3 participants
  • l

    Lilly

    11/26/2021, 12:38 AM
    Note: It's Kotlin related because of the
    internal
    visibility modifier. Is it intended that test classes from app/src/test/java/ can access internal classes from app/src/main/java? If yes, can someone tell me why Android Studio marks those references as unresolved? The test runs without any problems! It's a fresh android project.
    Android Studio Chipmunk | 2021.2.1 Canary 5
    Build #AI-212.5457.46.2112.7905983, built on November 11, 2021
    Runtime version: 11.0.12+7-b1504.28-7817840 amd64
    VM: OpenJDK 64-Bit Server VM by Oracle Corporation
    Windows 10 10.0
    GC: G1 Young Generation, G1 Old Generation
    Memory: 4096M
    Cores: 16
    Registry: external.system.auto.import.disabled=true
    Non-Bundled Plugins: com.andrey4623.rainbowcsv (2.0), Statistic (4.1.7), com.github.setial (4.0.2), CheckStyle-IDEA (5.58.0), dev.polek.adbwifi (1.2.4), krasa.CpuUsageIndicator (1.14), kotest-plugin-intellij (1.1.44-IC-2021.1), izhangzhihao.rainbow.brackets (6.21)
    e
    2 replies · 2 participants
  • m

    myanmarking

    11/26/2021, 12:43 PM
    does any1 know any tutorial for custom serialization. For big collection, to use a flow instead of a list ?
    d
    1 reply · 2 participants
  • r

    Raul Macías

    11/26/2021, 7:19 PM
    Hi everybody, i have a doubt. Do you know how I can delete the sharepreferences before the app closes, that is, in the onDestory ()?
    :not-kotlin: 2
    c
    a
    3 replies · 3 participants
  • m

    Mehdi Haghgoo

    11/27/2021, 11:44 AM
    I am doing my best to do database room stuff in coroutines, but my project crashes every time. It thinks I'm touching database in the main thread. I swear I'm not!
    java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
    I'm doing all insertions in coroutine contexts like:
    fun removeMessage(message: Message) = viewModelScope.launch{
        repository.remove(message)
    }
    j
    k
    +3
    10 replies · 6 participants
  • a

    Arpit Shukla

    11/28/2021, 4:33 AM
    How can I convert
    Map<String, Any>
    to a data class using kotlinx.serialization?
    z
    2 replies · 2 participants
  • a

    Akash

    11/29/2021, 11:21 AM
    Hey Floks, Need Some help on android webview. I’m facing an issue, Web page is not scrolling in webview with some devices. I’m hoping those devices are running on low memory and device is taking long time to response. Anyone can suggest how to solve this issue. This is happening with my library/AAR which is consume by multiple apps.
    :not-kotlin: 5
    k
    2 replies · 2 participants
  • t

    Tower Guidev2

    11/29/2021, 3:10 PM
    Good afternoon everyone... I have an issue with Kotlin serialisation in my android application
    e
    8 replies · 2 participants
  • a

    amiracam

    11/29/2021, 10:45 PM
    not sure if this is the right channel, but I'm interested in Jetpack Compose multi platform but the objective is from one code base to deploy both a desktop and web app, is that currently possible ? much thanks
    a
    1 reply · 2 participants
  • m

    Mahmoud

    11/30/2021, 8:10 AM
    Hello everyone! I'm facing some bad performance since using compose on my Android app. I tried to reduce recompositions. Now i a have questions about this. Are modifiers costly in recompositions? On every recomposition every action on modifier like padding, background,... are reset and recalled. Some actions like onSizeChanged are called on every recomposition cause the previous size is reset. I tried to remember modifier and that reduces useless calls of onSizeChanged. Is it OK to remember modifiers?
    👀 1
    ➕ 1
    a
    2 replies · 2 participants
  • a

    Ankit Shah

    11/30/2021, 5:03 PM
    Hello everyone, can someone help me with this problem?https://stackoverflow.com/questions/70098161/know-the-type-of-biometric-login-type-before-building-prompt-in-kotlin
    m
    2 replies · 2 participants
  • a

    Alexander Black

    11/30/2021, 7:08 PM
    Hello all, has anyone else been running into
    java.lang.ClassCastException: java.util.ArrayList cannot be cast to kotlin.Resul
    ? Should I report this as a bug? I’m able to use the Kotlin result library without issue for many result types, but weirdly not with lists. I’m simply trying to return a result from an API request as a list, but having trouble doing so. My method looks like this
    suspend inline fun <reified T> get(route: String,
                                           block: RequestBuilder.() -> Unit = {}): Result<T> {
            if (networkReachability.isNetworkAvailable) {
                return try {
                    val options = RequestBuilder().apply(block)
                    val response = client.get<T>("$baseUrl$route") {
                        headers {
                            sessionId.value?.also {
                                append("API-KEY", it)
                            }
                        }
                        if (options.requestPerms.isNotEmpty()) {
                            options.requestPerms.forEach {
                                // this sets the URL query parameters
                                this.parameter(it.first, it.second)
                            }
                        }
                    }
                    Result.success(response)
                } catch (e: Exception) {
                    return handleError(e)
                }
            } else {
                return Result.failure(NetworkNotReachable)
            }
        }
    my
    T
    type in this case is a List
    e
    3 replies · 2 participants
  • a

    Ahmed Hassan

    11/30/2021, 10:41 PM
    Hello every one, would appreciate it if you can give me your opinion on the following matter. I want to decide which one of the following block of codes is better to use and why? 1st Block:
    nullableVarParent?.let { nonNullParent ->
    
        if (
        		nonNullParent.nullableValChildOne == null
             || nonNullParent.nullableValChildTwo == null 
        ) 
          return
        
        funcEx(
             nonNullParent.nullableValChildOne,   
             nonNullParent.nullableValChildTwo
        )
    }
    2nd Block
    if (
        		nullableVarParent?.nullableValChildOne == null
             || nullableVarParent?.nullableValChildTwo == null 
        ) 
          return
        
    funcEx(
         nullableVarParent?.nullableValChildOne!!,   
         nullableVarParent?.nullableValChildTwo!!
    )
    Some would think the second one is safe too because of the if condition, but is it better to use? Appreciate your support.
    l
    a
    6 replies · 3 participants
  • l

    Lilly

    12/01/2021, 12:23 AM
    [Solved] How can I work around
    'public' function exposes its 'internal' parameter type...
    internal interface Cache
    
    // Public API
    class API(private val cache: Cache) { // compile error --> 'public' function exposes its 'internal' parameter type
       // Cache is not exposed, just used internally
    }
    Cache
    is not part of the public API but it is used in the class that represents the public API (public API of the library/module). What options do I have?
    z
    2 replies · 2 participants
  • c

    Colton Idle

    12/01/2021, 6:06 AM
    I'm working with Dates for the first time in my app and I'm using Kotlin. What's the go to for being able to take a date and say "This date is 15 days from now". Should I be looking into java8 desugaring, or does kotlin have some sort of datetime classes that would work for my scenario?
    k
    s
    +1
    7 replies · 4 participants
  • r

    Remy Benza

    12/01/2021, 12:57 PM
    It seems like Kotlin Synthetics for Android Views does not work anymore in version 1.6. When using version 1.5.31 it works normally. I saw it was deprecated but should at least continue to work. Any suggestions to get it to working with v1.6? My error is in thread
    🎉 1
    u
    n
    +2
    8 replies · 5 participants
  • i

    iamraghavawasthi

    12/02/2021, 5:07 AM
    Hey folks I am trying to clean up my existing codebase I want to make this function more generic.This is my current implementation I want to remove the need to pass the kClass rather infer it directly from T I tried inlining but none of those approaches work
    s
    l
    3 replies · 3 participants
  • d

    dave08

    12/02/2021, 10:20 AM
    Hi! I'm trying to figure out whether the various getX functions in SharedPreferences might return null (and if the defValue can be null)? It seems like only getString and getStringSet are annotated with
    @Nullable
    for that... 🤔
    d
    3 replies · 2 participants
  • d

    dave08

    12/02/2021, 10:23 AM
    In the source code (it seems that it wouldn't bother Android if defValue was null... but why isn't it annotated like getString?):
    @Override
        public int getInt(String key, int defValue) {
            synchronized (mLock) {
                awaitLoadedLocked();
                Integer v = (Integer)mMap.get(key);
                return v != null ? v : defValue;
            }
        }
    k
    1 reply · 2 participants
  • n

    natario1

    12/02/2021, 4:09 PM
    Has anyone run into issues with
    kotlin.Metadata
    + proguard after updating to 1.6.0? We were following official advice, but now the annotation is not kept in bytecode anymore, which creates all sorts of issues.
    😒olved: 1
    1 reply · 1 participant
  • a

    Ankit Shah

    12/02/2021, 5:21 PM
    Hello Everyone, I am stuck in a problem in jetpack compose. How can I launch a suspend function in my viewmodel from a @Composable function as soon as the screen is Loaded? Solutions I have Tried:
    @Composable
    fun FollowInterestsContent(actions: MainActions,viewModel:UserOnboardViewModel){
       val coroutinesScope = rememberCoroutineScope()
       viewModel.setInterestsList(context)
    }
    This Returns 
    Suspend function 'setInterestsList' should be called only from a coroutine or another suspend function
    Next I tried is
    @Composable
    fun FollowInterestsContent(actions: MainActions,viewModel:UserOnboardViewModel){
       val coroutinesScope = rememberCoroutineScope()
       coroutinesScope.launch { viewModel.setInterestsList(context) }
    }
    This Returns 
    Calls to launch should happen inside a LaunchedEffect and not composition
    n
    2 replies · 2 participants
Powered by Linen
Title
a

Ankit Shah

12/02/2021, 5:21 PM
Hello Everyone, I am stuck in a problem in jetpack compose. How can I launch a suspend function in my viewmodel from a @Composable function as soon as the screen is Loaded? Solutions I have Tried:
@Composable
fun FollowInterestsContent(actions: MainActions,viewModel:UserOnboardViewModel){
   val coroutinesScope = rememberCoroutineScope()
   viewModel.setInterestsList(context)
}
This Returns 
Suspend function 'setInterestsList' should be called only from a coroutine or another suspend function
Next I tried is
@Composable
fun FollowInterestsContent(actions: MainActions,viewModel:UserOnboardViewModel){
   val coroutinesScope = rememberCoroutineScope()
   coroutinesScope.launch { viewModel.setInterestsList(context) }
}
This Returns 
Calls to launch should happen inside a LaunchedEffect and not composition
n

natario1

12/02/2021, 5:26 PM
Use
LaunchedEffect(viewModel) { viewModel.doStuff() }
.
a

Ankit Shah

12/02/2021, 5:29 PM
Thanks a lot @natario1, That helped 👍
View count: 4