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

    OG

    10/11/2022, 11:58 PM
    Hello there 👋 Was wondering if anyone could provide some insight on how we can customize the app launcher icon programmatically? Let's say we allow the user to select from a list of icons in the app on so screen, or allow them to select a color in the app, and then we want to replace the default launcher for our app... Is there a way to do this? Ive read online some different "hacks" but nothing full proof or intentionally supported by Google for this type of customization. Any insights would be much appreciated 🙌
    g
    • 2
    • 2
  • r

    rtsketo

    10/12/2022, 10:59 AM
    Sorry for :not-kotlin: , I saw #android and thought that was the place. Is there a channel suited for this question?
    s
    l
    • 3
    • 2
  • r

    Radoslaw Juszczyk

    10/13/2022, 6:16 AM
    Hey guys, is it ok to use kotlin getter like that (theoretical example):
    val isTooLate: Boolean
       get() = System.currentTimeMillis() > someTimestamp
    I find it confusing that hovering over it in the IDE gives: public final val isTooLate: Boolean which gives an impression that this value is going to be always the same - but it's not.
    v
    r
    • 3
    • 10
  • a

    Abdul Moeed

    10/13/2022, 7:17 AM
    Hi everyone, I am working on an app that gets data from an API every 10 seconds and then updates the UI accordingly. I currently have a while loop with a 10s delay that works infinitely.
    override suspend fun getBusStopModel(): Flow<Resource<SmartBusStop>> {
        return flow {
            while(currentCoroutineContext().isActive){
                try{
                    val data = api.getBusService(STOPID).toSmartBusStop()
                    emit(Resource.Success<SmartBusStop>(data))
                } catch (e: HttpException){
                    emit(Resource.Error(e.localizedMessage ?: "An unexpected error occurred"))
                } catch (e: IOException){
                    emit(Resource.Error("Couldn't reach server. Check your internet connection"))
                } catch (e: Exception){
                    emit(Resource.Error(e.stackTraceToString()))
                }
                delay(10000)
            }
        }
    }
    This is called and collected in the view model. I want to ask, is there any better way to achieve a periodic API call. I have looked into work manager a little bit
    r
    l
    +2
    • 5
    • 11
  • p

    Pabitra Ranjan Sahu

    10/14/2022, 5:03 AM
    Hi @channel, can anyone help me here ? I am trying to create one sample project in
    KMM (Kotlin Multiplatform Mobile)
    in Android Studio. I followed the steps to create this, But I am facing some issues while compiling the code. Here it is:
    'pod install' command failed with code 1.
    Full command: pod install
    Error message:
        [33mWARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
        Consider adding the following to ~/.profile:
        export LANG=en_US.UTF-8
        [0m
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/unicode_normalize/normalize.rb:141:in `normalize': Unicode Normalization not appropriate for ASCII-8BIT (Encoding::CompatibilityError)
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/config.rb:166:in `unicode_normalize'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/config.rb:166:in `installation_root'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/config.rb:226:in `podfile_path'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:105:in `markdown_podfile'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:30:in `report'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:66:in `report_error'
    	from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:396:in `handle_exception'
    	from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:337:in `rescue in run'
    	from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:324:in `run'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in `run'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/bin/pod:55:in `<top (required)>'
    	from /usr/local/bin/pod:23:in `load'
    	from /usr/local/bin/pod:23:in `<main>'
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/unicode_normalize/normalize.rb:141:in `normalize': Unicode Normalization not appropriate for ASCII-8BIT (Encoding::CompatibilityError)
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/config.rb:166:in `unicode_normalize'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/config.rb:166:in `installation_root'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/config.rb:226:in `podfile_path'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/config.rb:205:in `podfile'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:160:in `verify_podfile_exists!'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command/install.rb:46:in `run'
    	from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in `run'
    	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/bin/pod:55:in `<top (required)>'
    	from /usr/local/bin/pod:23:in `load'
    	from /usr/local/bin/pod:23:in `<main>'
            Please, check that podfile contains following lines in header:
            source '<https://cdn.cocoapods.org>'
             Please, check that each target depended on sharedKMM contains following dependencies:
    Thanks in advance.
    n
    s
    • 3
    • 5
  • k

    khiari youssef

    10/14/2022, 9:56 AM
    Hello people, any idea why Compose previews don't work in android modules ? unless i call the composable in the main android app module ?
    c
    • 2
    • 6
  • j

    Jhonatan Sabadi

    10/14/2022, 10:57 AM
    Hi, someone knows how to update
    lint-baseline
    files ? I already have generated files, but with changes in code, i would like to regenerate it, or update.
    r
    • 2
    • 4
  • b

    Ben Edwards

    10/14/2022, 11:04 PM
    Hi, I've been having this problem all day and can't figure it our. I have asked in other places but no joy (There is a link to the Stack Overflow question at the end). Ime really stuck and hoping someone here takes pity on me :). I've been following a tutorial that uses a provider to talk to a DB and use an observer to keep a RecyclerView up to date. Its a bit out of date so I've spent a few hours getting it (kind of working). I got as far as getting it working when there were no records in the DB (I pass null cursor to the RecycleViewAdapter and if this is the case it displays instructions in the list view). When I run it I get the instructions even though there are 2 records in DB (it should dhow the records). The problem is when I have data it does not seem to put it in the RecycleView.
    c
    • 2
    • 7
  • b

    Ben Edwards

    10/15/2022, 12:28 AM
    Can someone please give me some guidance on the 'Not Kotlin' reaction? This is the android channel and I am using Kotlin. Sorry, I'm confused. I thought this channel was for questions about Kotlin-Android development (I would understand if i had been asking XML or gradle questions). Just trying to understand so I don't post inappropriate stuff. Also, the other reaction was 'thread,-please. I get it, I should of posted a short message and put the rest in the comments but cant work out how to add a reply to by post when others have not replied, how do I do this?
    c
    e
    +4
    • 7
    • 16
  • a

    Aaron Waller

    10/16/2022, 9:16 AM
    I want to notify the user when the item already exists in the room database. The list is a Flow
    Flow<List<Favorite>>
    and I collect it in my ViewModel. Whenever the user adds a Favorite I execute this function in my VM:
    fun addToFavorite(favorite: Favorite, alreadyFavorite: () -> Unit, addedToFavorite: () -> Unit) {
        viewModelScope.launch {
    
            favoriteRepository.getFavorites().collect(){ favoriteList -> 
                if(favoriteList.contains(favorite)){
                    alreadyFavorite()
                }else{
                    addedToFavorite() 
                    favoriteRepository.insertFavorite(favorite)
                }
            } 
        }
    }
    Now the problem here is that favoriteRepostitory.insertFavorite() adds the item to the room database and triggers the getFavorites().collect. So an endless loop gets created and the item is added to the room database indefinitely. How can I get the result of my getFavorites Flow without using collect? Or is there any other way?
    a
    r
    • 3
    • 5
  • m

    Milo

    10/16/2022, 9:55 PM
    Do you have a repo where I can implement local notifications?
  • k

    Kulwinder Singh

    10/17/2022, 5:06 AM
    I’m getting very unwanted behaviour in ROOM database, actually i have updated version of room but below class/entity does not have any changes but i’m getting below error, It is saying that Expected value not equals to Found , but Entity class is same
    z
    • 2
    • 1
  • e

    Elio Maroun

    10/17/2022, 6:06 AM
    https://stackoverflow.com/questions/74065159/how-can-i-know-the-how-many-items-will-be-drawn-on-the-screen-so-i-can-put-a-cu
    • 1
    • 1
  • b

    Bharath Kandula

    10/17/2022, 11:12 AM
    https://kotlinlang.slack.com/archives/CJLTWPH7S/p1666004214065629
  • b

    brian

    10/17/2022, 12:52 PM
    Hello everyone I want to know how I can improve this code snippet. I am tasked with converting the java code to kotlin
    public class E2EEService {
        Context context;
        public EThree eThree = null;
        ApiService apiService;
    
        public E2EEService(@NotNull ApiService apiService, Context context) {
            this.apiService = apiService;
            this.context = context;
        }
    
        public void initE2EE(Callback<Void> initCallback) {
            Callback<User> requestCallback = new Callback<User>() {
                @Override
                public void onSuccess(User user) {
                    Function0<String> getToken = () -> user.virgilJwt;
                    EThreeParams eThreeParams = new EThreeParams(
                            user.uuid,
                            getToken,
                            context
                    );
                    E2EEService.this.eThree = new EThree(eThreeParams);
                    initCallback.onSuccess(null);
                }
    
                @Override
                public void onError(Throwable throwable) {
                    initCallback.onError(throwable);
                }
            };
    
            apiService.getUser(requestCallback);
        }
    • 1
    • 2
  • c

    Christian Würthenr

    10/17/2022, 2:03 PM
    I read stuff online on
    -Xobjc-generics
    to pass generic information to Objective-C code, but all examples seem to be outdated on how to set this flag. Does anyone have a recent example?
  • j

    Javier

    10/17/2022, 7:39 PM
    Hi, I want to share with you this repo that improves Server Driven UI with compose, please take a look and share with me any comments or proposals https://github.com/javierpe/ArtGallery (e
  • s

    Sarthak Gupta

    10/18/2022, 7:45 AM
    Does anyone have any experience with Frida or Anti hooking detection in android ?
  • g

    Greg Rynkowski

    10/18/2022, 4:19 PM
    Is there a way to find out from just opened app, what are the intent details used to open that app? E.g. the app can have multiple activities, I would like to know which one was requested when the app process starts.
    p
    • 2
    • 2
  • i

    ikechukwu Wami

    10/18/2022, 6:25 PM
    👋 Hello, team! I feel glad to be here.
  • d

    Daniele Segato

    10/19/2022, 8:00 AM
    Is there a reason for
    lintPublish()
    to be ignored in multi-module projects?
    :myLib
    <--- module with a library (using
    lintPublish(project(":myLib-lint")
    )
    :myLib-lint
    <--- lint checks module for my library
    :featureX
    <--- some library including
    :myLib
    as dependency lint checks are not performed in
    :featureX
    module unless I manually
    lintChecks(":myLib-lint")
    in addition to the dependency on
    :myLib
  • d

    Daniele Segato

    10/19/2022, 8:39 AM
    I'm using version 1.4.0 of the orchestrator. When I launch my test on my Pixel 2 (real device) all test run as expected. When I launch the same tests on my Pixel 4 (real device) no test is found / run. The Pixel 2 is running on Android 11 (API level 30) and the Pixel 4 on Android 13 (API level 33). My test only limit SDK level above 23 so they should both run the same tests. If I remove the
    execution = "ANDROIDX_TEST_ORCHESTRATOR"
    all test run but they fail (on both devices) because I need
    testInstrumentationRunnerArguments += "clearPackageData" to "true"
    I'd appreciate any suggestion. Thanks EDIT: nevermind, apparently I had to use a newer / non stable version of orchestrator (and/or) runner
  • v

    Vikas Rathod

    10/19/2022, 1:16 PM
    👋 Hello, team!
  • k

    Kayacan Kaya

    10/19/2022, 8:54 PM
    Hello! I am playing around
    WorkManager
    nowadays. I was just wondering if you have any recommended design patterns/code samples that you have used in your projects for injecting/using class instances into your
    Worker
    classes without the use of any dependency injection frameworks. Those classes can be repositories, data sources, etc, that may have executions of IO operations. Worth to mention: what I see, in general, is either the use of
    Hilt
    to inject the instances of classes to the constructors of `Worker`s or using singletons (kotlin objects) to make function calls. I am asking for other alternatives to use. Note: it is important to note that I am asking this question for Periodic Worker which complicates the usecase as I am imagining.
  • c

    Christy K

    10/19/2022, 9:33 PM
    Anyone have tips for connecting to a local server through the android emulator. I feel like I’ve used every stackoverflow trick out there but most the posts are old. I tried plugging in my wifi ip address in place of local host in my code. Using retrofit to make the api call. I also tried the 10.0.2.2 trick which tells the emulator to connect to the computers wifi. Still not working. Getting an error saying failed to connect. I have the spring boot server running through my terminal.
  • c

    Christy K

    10/19/2022, 9:39 PM
    Would it help if I showed my kotlin code api call??
    e
    k
    g
    • 4
    • 5
  • j

    Jung Danny

    10/20/2022, 4:15 AM
    1. When creating a
    StateFlow
    with
    stateIn
    , and you want the flow producer to be active all the time (even when the app is in the background), what coroutine scope should be used? 2. When observing to the above
    StateFlow
    , even though the flow producer would live forever, can you still use
    repeatOnLifecycle
    in the UI to safely unregister?
    g
    • 2
    • 2
  • g

    Greg Rynkowski

    10/20/2022, 10:28 AM
    I used to write some utils in the past in groovy and import them to build.gradle with
    apply from
    , eg.
    apply from: "$rootDir/gradle/getversion.gradle"
    I still keep my app config in Groovy's build.gradle, but I would like to write my utils in kotlin. Can I import kts files from build.gradle?
    • 1
    • 1
  • s

    Sky

    10/20/2022, 11:08 AM
    Hi I have a delete request that works fine, but when I make subsequent delete calls to an item that has already been deleted in the API, I get an Exception, and the app crashes. I tried handling the error using Try/Catch with different exceptions eg(HttpException, IOException, etc) to prevent the app from crashing but it doesn't seem to work.
    private fun deleteFavourite(
        favourite: GetFavourite?,
        viewModel: WallpapersSharedViewModel
    ) {
        //handling 404 error in case of subsequent Delete request
        try {
            if (favourite != null && !favourite.isEmpty()) {
                val favouriteId = favourite.get(0).id
                viewModel.deleteFavourite(favouriteId)
                Log.i("hiiiiyaa", "deleted${favouriteId}")
            }
        }
        catch (e: HttpException){
            Log.i("hiiiiyaa", "cannot find item to delete in the Api")
        }
    }
    Error:
    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.catexplorer, PID: 28492
        retrofit2.HttpException: HTTP 400 
            at retrofit2.KotlinExtensions$await$2$2.onResponse(KotlinExtensions.kt:53)
            at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:161)
            at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
          ............
    p
    • 2
    • 15
  • s

    Slackbot

    10/20/2022, 2:18 PM
    This message was deleted.
Powered by Linen
Title
s

Slackbot

10/20/2022, 2:18 PM
This message was deleted.
View count: 4