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

    Kamil Kalisz

    02/02/2021, 3:25 PM
    Hi all, I have question about “Managed Publishing” In google play, I wanted to fully automate release process but it can’t find anything about this in Google Play Developer API. Do you know of there is possibility to use managed publishing from API ?
    :google: 3
    :stackoverflow: 2
    m
    7 replies · 2 participants
  • s

    Simone Summo

    02/02/2021, 4:13 PM
    Hi all, I’ve switched to Android Studio Preview to use Jetpack Compose but I’m having problems with UI Testing in Espresso. On Google I couldn’t find anything, I think it’s some sort of bug of the AGP 7.0. The error refers to androidx.test.internal.platform.tracker.UsageTracker. NoClassDefFoundException
    g
    1 reply · 2 participants
  • m

    Mark

    02/03/2021, 10:57 AM
    I use Room primarily to convert SQL queries to
    Flow
    . However, I prefer to work directly with the support library APIs. How to convert a generic query to a
    Flow
    (either using a 3rd party library or building from scratch)?
    m
    i
    6 replies · 3 participants
  • r

    Rodri Represa

    02/03/2021, 1:48 PM
    Hi guys, i have a horizontal
    recyclerview
    with some cards (height =
    match_parent
    ) but i would like to add a
    marginBottom
    only in case the android device screen is big (example 20:9). How can i do that?
    :stackoverflow: 1
    1 reply · 1 participant
  • s

    Slackbot

    02/03/2021, 1:55 PM
    This message was deleted.
    s
    1 reply · 2 participants
  • g

    Giovani Guerra

    02/03/2021, 5:39 PM
    How to write this with Kotlin?
    static {
        AppCompatDelegate.setDefaultNightMode(
            AppCompatDelegate.MODE_NIGHT_NO);
    }
    public class MyApplication extends Application {
    }
    :google: 5
    d
    h
    2 replies · 3 participants
  • m

    myanmarking

    02/04/2021, 1:20 PM
    hello. does any1 know the name of the gradle task to run when generating the viewbinding classes ?
    a
    d
    7 replies · 3 participants
  • a

    André Thiele

    02/04/2021, 9:57 PM
    Whats the easiest way to achieve a fully transparent status bar? currently it looks like this: (this is inside a fragment which hosts a map fragment)
    :stackoverflow: 3
    2 replies · 1 participant
  • c

    Carlos Bedoy

    02/05/2021, 1:34 AM
    Hi everyone! I’m facing a weird issue, we used to use
    kotlinx.synthetic
    , (yeah! but is deprecated now), hence we start to migrate to viewBinding (honestly much better), but I’m facing next issue. I have a fragment such contains a MapFragment itself like this..
    <androidx.cardview.widget.CardView
        android:visibility="visible"
        .....
        app:layout_constraintTop_toTopOf="parent">
    
        <fragment
            android:id="@+id/onTheWayMap"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </androidx.cardview.widget.CardView>
    Before with
    kotlinx.syntheti
    we only invoke following lines:
    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
        ): View? = inflater.inflate(R.layout.a_fragment, container, false)
    
    
    val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
            mapFragment?.getMapAsync { //mapFragments never null
                googleMap = it
                ...
    Since we’re migrating to
    viewBinding
    , keeping same code above, mapFragment always is null, anyone here had faced same issue?, do you guys know how to fixed?, what can be wrong?
    private val binding by lazy {
            FragmentOnTheWayBinding.inflate(LayoutInflater.from(context))
        }
        override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
        ): View? = binding.root
    
    
    val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
            mapFragment?.getMapAsync { //always null
                googleMap = it
    f
    h
    2 replies · 3 participants
  • t

    tank777

    02/05/2021, 4:08 AM
    Hello Can any one help me to convert the bluetooth remove bond java code to Kotlin?
    Method m = device.getClass().getMethod("removeBond", (Class[]) null);
     m.invoke(device, (Object[]) null);
    t
    1 reply · 2 participants
  • t

    Tiago Nunes

    02/05/2021, 11:34 AM
    Hi everyone, I'm currently stuck in a "simple" use case using Hilt: I want a Retrofit service singleton, which takes an OkHttpClient. The OkHttpClient has an interceptor, which uses the Retrofit service singleton (to make a certain request inside the interceptor) The problem is: -> The OkHttpClient takes a Retrofit as argument -> The Retrofit takes an OkHttpClient as argument Cheers
    l
    2 replies · 2 participants
  • f

    Florian

    02/05/2021, 3:19 PM
    val bookmarks = repository.getAllBookmarkedArticles()
            .stateIn(viewModelScope, SharingStarted.Lazily, emptyList())
    Is it bad to initialize with
    emptyList()
    ? This is data from Room, hence it has no loading state
    o
    d
    6 replies · 3 participants
  • t

    Travis Griggs

    02/05/2021, 8:57 PM
    I've inherited an Android kotlin app, and am scrambling up the learning curve (done quite a bit of iOS). I need to make one simple GET request, not on the main thread of course. Is there a simple/idiomatic/not-too-bleeding-edge/lightweight/reliable go to for this kind of thing? I found okhttp and will probably use it unless there's a better suggestion. it looks pretty well supported, but it is originally a java library, and i wondered if there was something more kotlin-esque
    j
    l
    +3
    80 replies · 6 participants
  • w

    WukongRework.exe

    02/06/2021, 12:26 AM
    Hey guys im getting this really weird error on android for my robotics team (FTC specifically) I am trying to call the invoke operator from the companion object in
    override val keys: Keys get() = GamePadKeysOld(gamepad = gamepad)
    and it gives me a
    Sealed types cannot be instantiated
    error when building the android app I tried a small test case in a kotlin playground ( https://pl.kotl.in/8VWvKtOqm ) and set both versions to 1.4.30 and in the playground the error does not pop up and successfully runs Is there a reason for this and a way to fix? (I would like to keep it as an invoke call though just changing the function name is the solution I am currently using) Thanks in advance!
    Gamepad.kt
    f
    1 reply · 2 participants
  • j

    Jason

    02/06/2021, 1:46 AM
    Duration.toMinutespart
    is very useful in Java . Why Kotlin does not have such of this useful function ???
    t
    1 reply · 2 participants
  • j

    Jason

    02/06/2021, 1:47 AM
    Actually, I want to convert seconds Int to
    mm:ss
    such as : 300 seconds ->
    05:00
    a
    2 replies · 2 participants
  • l

    Law Gimenez

    02/06/2021, 1:06 PM
    Hi everyone! Can you recommend me an alternative to Jsoup? It seems outdated and not working properly with sites behind Cloudflare.
    :stackoverflow: 2
    a
    1 reply · 2 participants
  • i̇

    İsmail KOYUNCU

    02/06/2021, 3:22 PM
    Hi all. I want to learn about the mobile app. Wich one the videos or documents. Who is can prefer me . ? Thanks
    :stackoverflow: 2
    :google: 2
    m
    2 replies · 2 participants
  • j

    Joshua

    02/06/2021, 4:15 PM
    Can anyone explain why I can't open android studio... this makes me mad. I reinstalled andriod studio, tried to add enviroment variables even though it has worked before. Restarted my computer... but still this problem. Woud appreciate all help. I tried to google but the solutions wont work for me...
    o
    5 replies · 2 participants
  • t

    Tiago Nunes

    02/06/2021, 8:36 PM
    Hi everyone, quick question for which I can't find the answer on Google: When using Navigation API, and SafeArgs:
    val args: SomeFragmentArgs by navArgs()
    Does the
    args
    field keep its values after the activity gets killed by the system and recreated? In other words: does the Bundle sent to the Fragment survive? Cheers
    i
    a
    +1
    8 replies · 4 participants
  • f

    Florian

    02/06/2021, 10:25 PM
    I have 3 fragments in my bottom nav and their ViewModels stay in memory to preserve their state (the fragments are only detached, not removed). Is it okay that these ViewModels keep getting database updates even if the fragment is not active? I'm using the
    stateIn
    operator so that a Flow that starts fetching new data doesn't cancel when we switch screens. But after that remote fetch is done, the Flow will keep emitting cached data from the DB (which could get updated indirectly from another screen) even if the fragment is not active.
    o
    e
    3 replies · 3 participants
  • m

    Mostafa Hadian

    02/07/2021, 12:53 AM
    Hi 👋 , I was wondering if anyone has experience with Server-driven theming in Android apps? I want to be able to fetch the Primary/Secondary colours from the API and apply to the application.. The usecase is for theming a white-label app 🤔 …
    :stackoverflow: 1
    e
    5 replies · 2 participants
  • t

    Tiago Nunes

    02/07/2021, 4:36 PM
    Hi everyone, imagining this senario: -> I have a table in Room Database called "UserApplicationPreferences", where I keep configuration options for each user, and a loggedIn boolean; -> When a user enters the App, a query will be executed to find out if there is any UserApplicationPreferences with the flag loggedIn. -> If (or when) there is a loggedIn user, I want the corresponding UserApplicationPreferences instance to be synchronously available, everywhere in the app. -> Whenever the user changes their preferences, the saved instance should change (automatically, preferably). I was thinking the saved instance could be just the Flow returned in the Dao, but then to get its value I need to call collect() which is asynchronous (makes sense). Is there some way to like always be collecting from the flow and updating the instance (which will be in the Repository) or something like that? My goal is to: -> Have synchronous access to the UserApplicationPreferences (as I would when using SharedPreferences) -> Minimize queries to database (in-memory caching the up-to-date UserApplicationPreferences instead of running the query to get the up-to-date UserApplicationPreferences each time) This is working as I intended. There is no way this is good practice, right?...
    @Singleton
    class UserApplicationPreferencesRepository @Inject constructor(
        private val dao: UserApplicationPreferencesDao,
    ){
        var loggedInUserPreferences: UserApplicationPreferences? = null
            private set
    
        init {
            CoroutineScope(SupervisorJob() + <http://Dispatchers.IO|Dispatchers.IO>).launch {
                dao.getLoggedInFlow().collect {
                    loggedInUserPreferences = it
                }
            }
        }
    }
    m
    2 replies · 2 participants
  • l

    loloof64

    02/08/2021, 9:59 AM
    Hi everybody ! I've got this build.gradle from a React Native project. It worked before I upgrade inside to latest Gradle version Android Studio. (Android Gradle Plugin)
    app build.gradle
    a
    4 replies · 2 participants
  • s

    Slackbot

    02/08/2021, 1:04 PM
    This message was deleted.
    :google: 4
    :stackoverflow: 3
    t
    1 reply · 2 participants
  • j

    Joshua

    02/08/2021, 1:07 PM
    Hey guys, I'm trying to understand styles in android. This is the following style I created for my button.
    <style name="OrangeButtonPrimary">
            <item name="android:textColor">@color/white</item>
            <item name="cornerRadius">8dp</item>
            <item name="backgroundColor">#FC7E2F</item>
            <item name="android:textAllCaps">true</item>
        </style>
    However, when I add the style to my button nothing happens. I am therefor wondering whether I did something wrong or not?
    :google: 2
    :stackoverflow: 2
    u
    1 reply · 2 participants
  • a

    Abhinav Bhadauria

    02/08/2021, 2:23 PM
    Hey, I need help in paging 3 lib , I want to update the pagingdata and then want to reflect in adapter which is not happening rightnow
    :stackoverflow: 3
    :google: 1
    s
    21 replies · 2 participants
  • t

    Tiago Nunes

    02/08/2021, 6:33 PM
    Hey everyone, so there's this "new" way to apply plugins in Gradle right?
    plugins {
        id "org.jetbrains.kotlin.android" version "$kotlin_version"
    }
    I love the fact that it doesn't require me to change the classpath in project-level build.gradle ...But, does it work for every plugin? If it does, how would I do this?
    id "androidx.navigation.safeargs.kotlin" version "2.3.3"
    (Plugin [id: 'androidx.navigation.safeargs.kotlin', version: '2.3.3'] was not found in any of the following sources:)
    j
    k
    +2
    32 replies · 5 participants
  • v

    Vivek Sharma

    02/09/2021, 1:58 PM
    I have like 
    2 flows
     and I want to observe their changes with 
    flatMapLatest
    , if either of them emit new value, I want to trigger some action, but how can I observe on 
    2 flows
     , should I combine them ? how can I do it
    o
    6 replies · 2 participants
  • l

    Lucien Guimaraes

    02/09/2021, 5:14 PM
    Hello ! Regarding android permissions since Android 6 users can decide to denied and check "never ask again" for a permission you asked. This is even more relevant with Android 11, which is the solution by default when user deny your permission. I saw on some apps, that they are able to ask for a permission and if it's denied (at runtime or even before the app is started) they open the settings app, and the user can enable the permission from there. I haven't seen any official documentation for this specific behaviour. How do they detect the permission has been fully denied (prompt can't be shown again) ? Thanks !
    :stackoverflow: 3
    l
    2 replies · 2 participants
Powered by Linen
Title
l

Lucien Guimaraes

02/09/2021, 5:14 PM
Hello ! Regarding android permissions since Android 6 users can decide to denied and check "never ask again" for a permission you asked. This is even more relevant with Android 11, which is the solution by default when user deny your permission. I saw on some apps, that they are able to ask for a permission and if it's denied (at runtime or even before the app is started) they open the settings app, and the user can enable the permission from there. I haven't seen any official documentation for this specific behaviour. How do they detect the permission has been fully denied (prompt can't be shown again) ? Thanks !
:stackoverflow: 3
l

Larry Schiefer

02/09/2021, 5:19 PM
Usually it's done by requesting the permission, getting
PERMISSION_DENIED
then calling
.shouldShowRequestPermissionRationale()
which will tell you if it is acceptable for you to tell the user why the permission is needed. Note that method will return
false
if you have never requested the permission - you have to have requested it and it been denied before it will return
true
.
✅ 2
l

Lucien Guimaraes

02/09/2021, 5:27 PM
oh thanks, I saw the API
shouldShowRequestPermissionRationale
on the official documentation but it wasn't clear that it will return
true
if the permission was already asked.
View count: 6