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

    Trieu Tran

    03/17/2021, 8:36 AM
    Hi guys, i try to use BiometricPrompt, but when i touch the fingerprint sensor the dialog disappear. Anyone know how to get rid of it, Thanks
    :google: 3
    :stackoverflow: 2
    :not-kotlin: 6
    g
    • 2
    • 1
  • c

    Chris

    03/17/2021, 11:18 PM
    Hi,Is there a library to replace Android Handler.callback?
    z
    • 2
    • 4
  • a

    Anshulupadhyay03

    03/18/2021, 9:43 AM
    is there any library to load svg images? I have checked that Glide doesn't have SVG support and using this one https://github.com/qoqa/glide-sv , i am not able to access GlideApp.
    u
    v
    s
    • 4
    • 7
  • s

    Seuan Rahman

    03/18/2021, 10:47 AM
    Hello everybody, what is the easiest way to implement zooming function to an imageView?
    :google: 4
    s
    d
    • 3
    • 4
  • m

    Marko Novakovic

    03/18/2021, 1:49 PM
    would you say this is good practice?
    class OnActiveTriggerLiveData<T>(
        private val doOnActive: MutableLiveData<T>.() -> Unit
    ) : MutableLiveData<T>() {
    
        override fun onActive() {
            super.onActive()
            doOnActive()
        }
    }
    and you have instance of this inside your
    ViewModel
    like so:
    class AccountViewModel(val repo: Repo) : ViewModel() {
        private val _account = OnActiveTriggerLiveData<Account> { value = repo.account }
        val account: LiveData<Account>
            get() = _account
    So every time view(Activity/Fragment) hits
    onStart
    account will be updated with the newest value so you don’t have to expose method from
    ViewModel
    and call it from
    onStart
    nor
    onResume
    You just observe
    LiveData
    and not care about anything else
    a
    • 2
    • 2
  • r

    Ragvax

    03/18/2021, 1:55 PM
    Hey guys, can anybody help me with this one? I'm trying to figure out what's the best way to do this. https://stackoverflow.com/questions/66643570/how-to-properly-migrate-from-livedata-to-flow-that-has-map-transform
    r
    • 2
    • 1
  • l

    luke_c

    03/18/2021, 5:12 PM
    I just saw AGP 4.1.3 has been released, and like the other point releases for 4.1 I can’t find a changelog anywhere. The official release page only shows 4.1 https://developer.android.com/studio/releases/gradle-plugin#4-1-0 Are these posted anywhere else or can they be added please? It’s frustrating trying to find out whether an issue you previously had has been fixed or not
    s
    • 2
    • 2
  • e

    Ernestas

    03/18/2021, 6:31 PM
    Hello guys, is there any way to show a BottomSheet dialog from the actual bottom of the screen, not the fragment itself when using a BottomNavigationView with a FragmentContainer?
    a
    • 2
    • 2
  • k

    Kevin Janvier Chinabalire

    03/18/2021, 7:22 PM
    how do i store an object using
    datastore
    i have tried this
    val getUsers: Flow<User?>
            get() = dataStore.data.map { preference ->
                preference[USER_DETAILS]
           }
    for retrieving and for saving
    dataStore.edit {
       it[USER_DETAILS] = MyObject
       }
    but nothing is working …
    t
    • 2
    • 2
  • k

    Kevin Janvier Chinabalire

    03/18/2021, 7:35 PM
    i have see protocol buffers Protocol Buffers | Google Developers
    m
    • 2
    • 1
  • t

    truongpham_se

    03/19/2021, 3:20 AM
    Hey guy, Could anybody help me resolved this problem.?
    :not-kotlin: 2
    i
    k
    +2
    • 5
    • 19
  • p

    Parth Gupta

    03/19/2021, 6:30 AM
    Hi all I want to create a hybrid application which can run on both ios and android using kmm for shared business logic. Can I use flutter along with kmm to have common UI for both platforms?
    👀 1
    u
    • 2
    • 6
  • a

    Anshumaan Kumar Prasad

    03/19/2021, 9:50 AM
    Hello ppl! I'm just a beginner in Kotlin, want to play music in my app, with only one touch (button) Pl let anyone get me know how can I go ahead?
    :google: 2
    :stackoverflow: 1
    c
    • 2
    • 2
  • s

    Seuan Rahman

    03/19/2021, 12:36 PM
    What should I use to save a switch button state in the app? Im only finding how to do it in java and not kotlin on the web
    f
    • 2
    • 3
  • f

    Felix Thomas

    03/19/2021, 12:39 PM
    Hi all, I’m trying to find a way to create a self-updating ObservableBoolean for the device’s network status. There’s a lot of talk about using a
    <http://android.net|android.net>.conn.CONNECTIVITY_CHANGE
    intent, however that’s been deprecated. Anyone got any good ideas on how to implement this on devices running Android N or over?
    s
    • 2
    • 1
  • l

    Lena Brusilovski

    03/19/2021, 6:00 PM
    ios has a method called “deinit” is there a way to invoke it using kotlin code ?
    o
    • 2
    • 1
  • a

    Arun

    03/19/2021, 7:59 PM
    Hi everyone. While using preferences DataStore, I’m facing IOException
    ..preferences_pb.tmp could not be renamed to....preferences_pb
    . It’s exactly as in https://stackoverflow.com/questions/66446999/could-not-be-renamed-to-data-user-0-app-android-githubservice-files-datastore-m. Has anyone come across such issue?
    m
    • 2
    • 1
  • d

    David Martin

    03/20/2021, 5:35 AM
    I'm facing a really strange bug, the day before yesterday I was coding using an old version of AS(I don't remember the version), this morning I've updated to the latest version 4.1.3. My code isn't being changed anything:
    val fragmentTransaction = fragmentManager!!.beginTransaction()
    Before I'm was able to navigate between fragments using above code but today isn't, how on the Earth has a bug like this? Then I changed my code to using childFragmentManager and parentFragmentManager but nothing happen, there is no logcat, no error, just can't navigate between fragments anymore, I've debuged and every variables aren't null. Is there anyone facing this bug? any solution works around? thanks in advance!
    :stackoverflow: 4
    c
    • 2
    • 2
  • s

    Slackbot

    03/20/2021, 5:15 PM
    This message was deleted.
    j
    a
    • 3
    • 2
  • t

    therealbluepandabear

    03/20/2021, 8:47 PM
    how much knowledge of kotlin do I need before I can start learning android dev do you think? I know these things: • variables, strings, if-else statements, when statements, for loop, while loop, functions, lists and sets, also maps, null safety, classes, interfaces, anonymous objects, abstract classes, functional programming, lambdas, inlined lambdas, lazy initialisation, unsigned, exceptions, try catch blocks, anonymous functions, basic generics (but not in and out), sealed classes, inner classes, data classes, companion objects, objects, difference between how companion objects and regular objects are instantiated, polymorphism, inheritance, Is this enough for me to start? Or is more expansive knowledge needed. For example I'm not familiar with coroutines and I only have basic knowledge with generics.
    o
    e
    l
    • 4
    • 6
  • d

    Dhanya S Pillai

    03/21/2021, 9:51 AM
    Im facing an error below, please tell what are the possible causes for this error java.lang.IllegalStateException: Backend Internal error: Exception during file facade code generation My kotlin version :
    1.4.21
    Android studio : 4.1.2 Note: Im not using jetpack compose
    a
    • 2
    • 2
  • s

    Steve

    03/22/2021, 10:24 PM
    When writing an Android test JUnit rule, is there a good way to write to SharedPreferences in it? Writing to SharedPreferences requires a Context
    :not-kotlin: 6
    e
    c
    • 3
    • 4
  • t

    Tony Kazanjian

    03/23/2021, 1:26 AM
    Hi all. Can anyone tell me what dependency I need for
    androidx.test.annotation.UiThreadTest
    ? I currently have
    androidTestImplementation 'androidx.test:annotations:1.3.0'
    in my module's build.gradle file, but I cannot find the needed annotation. Edit: Nevermind, SO to the rescue:
    'androidx.test:rules:1.3.0'
    I guess a follow-up question would be, how the hell would I have found that out otherwise? The documentation points me to the annotations package. Why wouldn't this annotation be there?
    :stackoverflow: 1
    :not-kotlin: 4
    t
    • 2
    • 2
  • a

    Abdalla Hassanin

    03/23/2021, 1:16 PM
    Hi everyone, I want to learn the Testing in android, but I don't know anything about it, so I want you to suggest something to start studying the Testing ??
    p
    p
    • 3
    • 3
  • h

    Hossein Amini

    03/23/2021, 5:37 PM
    Hi, I’m trying to test KMM, when I create a new KMM project all gradles have many red lines like the attached image but there is no problem to build the project. Is there any way to fix it?
    r
    f
    k
    • 4
    • 8
  • l

    Lilly

    03/24/2021, 12:12 PM
    Is it possible to define an abstract function as extension function?
    sealed class Foo {
        abstract fun bar()
    }
    
    class A : Foo()
    class B : Foo()
    
    /* in another file */
    
    fun A.bar() {
      // implementation
    }
    It seems it's not possible but maybe there is something similar? I just want to move the implementation of
    bar()
    to other files because the LOC for the implementation is huge. I want to avoid a file with thousands of LOC. Any ideas?
    m
    s
    • 3
    • 6
  • d

    Dustin Lam

    03/24/2021, 7:35 PM
    what do you mean by "keep fetching"?
    s
    d
    • 3
    • 20
  • s

    Scott Kruse

    03/24/2021, 10:37 PM
    Is there a way to easily make a textview's text transparent if the textview has a background color? The goal is for text to be transparent, thus showing the parent view's background
    🙌 1
    :not-kotlin: 3
    l
    o
    • 3
    • 6
  • m

    Mateusz Holak

    03/25/2021, 8:32 AM
    Hi. I need some advice with bluetooth low energy. I need do some communication with device in background mode. I was wondering if exist better solution than background task where periodically start ble scan and if found device, connect to them and check if data exist on it. I found this article https://developer.android.com/reference/android/bluetooth/le/AdvertiseData but never use it and wanted to ask you some details. Do you know its possible to check that device has some new data during scan process or somehow got information when new data is coming on device?. Becuase i think background ble scanning is heavy solution and maybe is something better than scanning all the time, trying to establish connection and keeping subscription on characteristics.
    k
    • 2
    • 11
  • j

    jean

    03/25/2021, 9:13 AM
    I read this article yesterday : https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda. I’m wondering in the case of using this in a view model
    val state: StateFlow<MyViewState> = myFlow
        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), MyViewState())
    does one stills need to use something like this from a view
    lifecycleOwner.addRepeatingJob(Lifecycle.State.STARTED) {
       viewModel.state.collect {
            // do something with the data
        } 
    }
    i’m not completely sure what
    SharingStarted.WhileSubscribed()
    implies regarding android and its life cycle
    m
    r
    • 3
    • 5
Powered by Linen
Title
j

jean

03/25/2021, 9:13 AM
I read this article yesterday : https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda. I’m wondering in the case of using this in a view model
val state: StateFlow<MyViewState> = myFlow
    .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), MyViewState())
does one stills need to use something like this from a view
lifecycleOwner.addRepeatingJob(Lifecycle.State.STARTED) {
   viewModel.state.collect {
        // do something with the data
    } 
}
i’m not completely sure what
SharingStarted.WhileSubscribed()
implies regarding android and its life cycle
m

Manuel Vivo

03/25/2021, 9:25 AM
This is one of the cases you should definitely use the new APIs. In the VM layer, you don’t know what
myFlow
is or how it’s implemented.
WhileSubscribed()
means that when there are no collectors available, the underlying flow will be cancelled.
If for some reason, you 100% want to keep the underlying producer active, use the new APIs, but change the
WhileSubscribed
to
Eagerly
or
Lazily
j

jean

03/25/2021, 9:29 AM
alright, thanks for the quick answer 🙂
👍 1
r

Remy Benza

03/26/2021, 8:35 AM
what if you convert the state flow in the example above to LiveData, and then you observe it from the Fragment
would that mean you dont need the new API's ?
View count: 1