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

    mohsenoid

    10/29/2021, 9:05 AM
    Hey Android Developers! I've been working on a YouTube channel for a month and would like to introduce it to you and get some feedback: https://www.youtube.com/c/AndroidDevelopmentLightningTipsAndTricks
    👍🏻 1
    👍 1
    t
    • 2
    • 3
  • s

    Slackbot

    10/29/2021, 2:04 PM
    This message was deleted.
    l
    j
    • 3
    • 2
  • a

    AmrJyniat

    10/29/2021, 6:54 PM
    What are the pros and cons of storing a DateTime as a timestamp in Room DB? is it good practice? because I heard that will lose control of timeZone if do so, how do you handle this process guys?
    h
    m
    • 3
    • 3
  • e

    Emanuel Frost

    10/29/2021, 7:24 PM
    ah found it, emit instead of tryEmit worked
    • 1
    • 2
  • s

    Sam

    10/30/2021, 7:52 PM
    Hello everyone. I have no experience with Pagination 3, I want to save data in the database, when there is a change I will save it to the database and it will automatically update to the UI. Is this possible with Pagination 3 + (Rxjava || Livedata)? Thanks.
    :not-kotlin: 3
    :kotlin-intensifies: 2
    s
    c
    • 3
    • 2
  • s

    shaarawy

    10/31/2021, 4:26 PM
    Hi there. In Some Android libraries i can find an api directory next to the src directory Does any body know what is the importance of that directory and the files inside it? https://github.com/chrisbanes/snapper/tree/main/lib/api https://github.com/square/logcat/tree/main/logcat/api
    a
    j
    c
    • 4
    • 7
  • t

    theapache64

    10/31/2021, 7:46 PM
    [✅ SOLVED] I am using Chainfire’s libsuperuser to write to a protected directory. but it doesn’t write content (can read though). Code inside the 🧵
    • 1
    • 2
  • z

    Zoltan Demant

    11/01/2021, 7:19 AM
    Has anyone managed to include the recipients email address when using
    ACTION_SENDTO
    in Android 12? The code is identical to the official documentation and has worked flawlessly before Android 12.
    :not-kotlin: 2
    👍 1
    • 1
    • 1
  • o

    Orhan Tozan

    11/02/2021, 10:32 AM
    The flow lifecycle article of @Manuel Vivo https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda gives this example of collecting multiple flows:
    // Listen to multiple flows
            lifecycleScope.launch {
                lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
                    // As collect is a suspend function, if you want to collect
                    // multiple flows in parallel, you need to do so in 
                    // different coroutines
                    launch {
                        flow1.collect { /* Do something */ }   
                    }
                    
                    launch {
                        flow2.collect { /* Do something */ }
                    }
                }
            }
    Is there anything wrong with doing this instead? :
    // Listen to multiple flows
            lifecycleScope.launch {
                lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
                    // As collect is a suspend function, if you want to collect
                    // multiple flows in parallel, you need to do so in 
                    // different coroutines
                    launch {
                        flow1.collect { /* Do something */ }   
                    }
                
                }
            }
            lifecycleScope.launch {
                lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
                    
                    launch {
                        flow2.collect { /* Do something */ }
                    }
                }
            }
    a
    i
    • 3
    • 3
  • s

    Sam Smallman

    11/02/2021, 3:49 PM
    Hey I have a .JAR that implements kotling-logging (https://github.com/MicroUtils/kotlin-logging), what do i need to do see the logs from the JAR in Android Studio.
    c
    • 2
    • 2
  • s

    Sergio C.

    11/02/2021, 5:59 PM
    How do we change PagingSource dynamically in Pager? I need to collect from one Flow and when searching/filtering select another flow
    e
    m
    • 3
    • 9
  • p

    Philip Dukhov

    11/03/2021, 12:59 PM
    Hello. I come from iOS development and am used to calling kotlin lambdas (e.g.
    val onAction: () -> Unit = { ... }
    ) as blocks. Is this naming clear to android developers? The word lambda in my head does not sound very nice in this context.
    r
    e
    +3
    • 6
    • 13
  • o

    Orhan Tozan

    11/03/2021, 1:45 PM
    I'm on Android Navigation 2.4.0-beta01 and when compiling, my enum navarg type's are not being compiled (unresolved reference). Anyone encountered this issue before? This is with SafeArgs ofcourse.
    :not-kotlin: 1
    f
    • 2
    • 2
  • u

    _shtomar

    11/03/2021, 10:02 PM
    Quick question folks: I am developing an SDK where I need to add Fragment into an Activity. FragmentManager is deprecated since API 26. Now get SupportFragmentManager is a function of support.AppCompatActivity. I don’t want to use deprecated class FragmentManager but can’t acces SupportFragmentManager from AppCompatActivity. What is the best way to go here?
    :not-kotlin: 4
    f
    a
    • 3
    • 4
  • i

    Ilya Gazman

    11/04/2021, 10:57 AM
    How are useful searches by a class name? Now with Android composable, the problem is even worse. The framework forces you to create methods with a capital letter in a stand-alone file.
    d
    e
    +2
    • 5
    • 13
  • s

    Sergio C.

    11/04/2021, 2:04 PM
    Whats the fastest method for deserializing data from Realtime Database?
    :kotlin-intensifies: 1
    :not-kotlin: 3
    g
    • 2
    • 9
  • f

    Fedora

    11/04/2021, 2:45 PM
    Hey guys, one question, is is possible to collect the data/values of a
    MutableStateFlow
    in 2 fragments of a viewpager?
    m
    a
    • 3
    • 5
  • m

    Maya Gorel

    11/05/2021, 8:16 AM
    Hello, What are you using for implementing expandable layout?
    h
    • 2
    • 2
  • r

    Ruben Quadros

    11/05/2021, 1:58 PM
    Hi guys,
    I keep getting java.lang.IllegalArgumentException: Key was already used. If you are using LazyColumn/Row please make sure you provide a unique key for each item.
    I am sure all the keys are unique and I even logged them to be sure. Also this happens when items are rapidly added to lazy column. Here is my sample code:
    @Composable
    fun UiComponent() {
        LazyColumn(
                    verticalArrangement = Arrangement.spacedBy(12.dp),
                    state = scrollState,
                    reverseLayout = true
                ) {
                    items(
                        items = viewmodel.messages,
                        key = { item -> item.hashcode() },
                        itemContent = { item: Entity ->
                            if (item.isDeleted) {
                                //show deleted ui
                            } else {
                                //show messages
                            }
                        })
                }
            }
    }
    
    VM {
    
        init { 
           observeDataFromDB()
        }
    
        private val _messages: MutableList<Entity> = mutableStateListOf()
        val messages: List<Entity> = _messages
    
    
        fun observeDataFromDB() {
            viewModelScope.launch {
                repo.getData().collect {
                    _messages.apply {
                        addNewItem(it)
                    }
                }
            }
        }
    
    }
    
    
    //extensions
    fun MutableList<Entity>.addNewItem(entity: Entity) {
        if (this.size >= MAX_SIZE) {
            removeLast()
        }
        Log("existing ${this.toList().map { "${it.hashCode()}" }}")
        Log("adding new ${entity.hashCode()}")
        this.add(0, entity)
    }
    
    //id is primary key
    data class Entity(val id: String, val isDeleted: Boolean, val message: String)
    Any help would be great! Have been stuck with this for sometime now and not sure how to proceed 😭 Have tried using
    id
    as the key and I still get the same error.
    a
    • 2
    • 3
  • v

    Vaios Tsitsonis

    11/05/2021, 10:52 PM
    Hello! I am trying to exclude some classes from an android apk. These classes are generated in the build folder. Exclude does not seem to work! Is there any sort of limitation/bug? I do not want to use proguard...
    :not-kotlin: 4
    a
    • 2
    • 4
  • g

    Gus

    11/06/2021, 12:53 PM
    Hi folks. I'm writing a JVM library using Kotlin, and this library is to be used on Android 5+ (API 21+) as well. I keep introducing changes that won't work on older versions of Android (like using `Path`s), and I don't realise until I try to upgrade the library on Android. Is there a tool that I can use in CI to spot any use of Java APIs not available on the versions of Android we support? I searched on Google but didn't find anything (maybe I could've used better keywords)
    :not-kotlin: 3
    s
    • 2
    • 1
  • a

    andrew

    11/06/2021, 9:40 PM
    Curious if there're any AOSP devs who work on anything fw or AOSP app related here. Trying to use IntelliJ for development in that area specifically for its first class Kotlin support, but indexing takes forever. Are there any exclusions anyone adds to their config so I can get cracking at development quicker?
    e
    • 2
    • 8
  • l

    Lukas K-G

    11/07/2021, 6:46 AM
    I have seen the Quodana static analysis tool

    https://youtu.be/_3ErSoKsoNQ▾

    and was wondering if this will work / make sense in an Android environment. Android was not mentioned in the video and I was thinking that this might be on purpose?
    k
    • 2
    • 1
  • a

    Ayden

    11/07/2021, 8:09 AM
    Hi everyone. Would my
    google-service.json
    being exposed when someone is doing reverse-engineer?
    :not-kotlin: 4
    e
    • 2
    • 1
  • i

    Iqbal Ahmed

    11/07/2021, 1:48 PM
    Hi Guys, Is it possible to play music on Google Home using 3rd Party App? I have requirement in which I have to play music on Google Home at particular time(Reminder). Or Is it possible to open google assistant using Intent? Thanks.
    :not-kotlin: 6
    • 1
    • 1
  • t

    TarunY

    11/08/2021, 8:57 AM
    HI Guys, The below error doesn't direct to my class file. Please suggest me how to solve this.
    m
    • 2
    • 2
  • z

    ziv kesten

    11/08/2021, 1:35 PM
    I want to make sure a TextView will not have single word per line. That means that if a text is long and is dropped to a second or third line, i want to check that there is more than one word in that line. Then break the text a word before that top ensure that there is more the one word in the last line. How can i count words in each line of a TextView?
    :not-kotlin: 3
    m
    k
    • 3
    • 3
  • d

    Doru N.

    11/08/2021, 4:29 PM
    Hey guys, I've a question regarding best practices on where should the thread switching to background (ie. coroutines context switching Dispatchers.IO) take place in a clean architecture app? Should that take place inside the Repository (in the data layer), or in the UseCase-s (domain layer)? Would really hope to hear your opinions on that with some Advantages / disadvantages presented.
    👍 1
    m
    p
    • 3
    • 5
  • s

    Skc

    11/08/2021, 11:16 PM
    Hi everyone 👋 I am working on migrating an existing android project to compose and followed the official guideline for dependencies (kotlin, agp etc). This is what my root gradle looks like,
    ext {
            compose_version = '1.0.1'
            kotlin_version = '1.5.21'
            agp_version = '4.2.2'
        } 
        dependencies {
            classpath "com.android.tools.build:gradle:$agp_version"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    compose dependencies
    implementation "androidx.compose.ui:ui:$compose_version"
        implementation "androidx.compose.material:material:$compose_version"
        implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
        implementation "androidx.compose.compiler:compiler:$compose_version"
        implementation 'androidx.activity:activity-compose:1.3.1'
        androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    It fails while compiling saying `this version (1.0.1) of the Compose Compiler requires Kotlin version 1.5.21 but you appear to be using Kotlin version 1.4.31 which is not known to be compatible. Please fix your configuration (or
    suppressKotlinVersionCompatibilityCheck
    but don't say I didn't warn you!).` Any hints where
    Kotlin 1.4.31
    might be coming from?
    s
    f
    • 3
    • 13
  • m

    My Nguyen

    11/09/2021, 8:28 AM
    Hi everyone. My company's application shows many notifications to the users. Some notifications have action buttons and we are using BroadcastReceiver to handle when users click the action button. Problem is that we are starting Activity from BroadcastReceiver but Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background. So there are some cases users click the button on the notification but nothing happens (activity not start). Does someone have any idea about this? Action button document URL: https://developer.android.com/training/notify-user/build-notification#Actions. Start activities restriction URL: https://developer.android.com/guide/components/activities/background-starts. Btw, I read the document of action button but the start activities restriction was not mentioned there. I think it should be mentioned so I created a document issue. https://issuetracker.google.com/issues/205606716
    :not-kotlin: 2
    r
    • 2
    • 9
Powered by Linen
Title
m

My Nguyen

11/09/2021, 8:28 AM
Hi everyone. My company's application shows many notifications to the users. Some notifications have action buttons and we are using BroadcastReceiver to handle when users click the action button. Problem is that we are starting Activity from BroadcastReceiver but Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background. So there are some cases users click the button on the notification but nothing happens (activity not start). Does someone have any idea about this? Action button document URL: https://developer.android.com/training/notify-user/build-notification#Actions. Start activities restriction URL: https://developer.android.com/guide/components/activities/background-starts. Btw, I read the document of action button but the start activities restriction was not mentioned there. I think it should be mentioned so I created a document issue. https://issuetracker.google.com/issues/205606716
:not-kotlin: 2
r

Rahul Rawat

11/09/2021, 8:36 AM
I generally make a PendingIntent for a transparent activity in notification clicks and that activity decides which activity to further start instead of using broadcast receiver. It works the same.
m

My Nguyen

11/09/2021, 8:40 AM
@Rahul Rawat not notification clicks, problem when click action button on notification.
r

Rahul Rawat

11/09/2021, 8:44 AM
It’s essentially the same thing. You might be using
PendingIntent.getBroadcast
to get pending intent of a broadcast receiver what I do usually is use
PendingIntent.getActivity
to an Intent Resolution Activity which has no UI and is Transparent so is not shown to the user and it re routes user to the right place.
m

My Nguyen

11/09/2021, 9:11 AM
@Rahul Rawat thank you very much! Look like you are right. Some of our actions should use PendingIntent.getActivity instead of PendingIntent.getBroadcas, because of only starting activity in the BroadcastReceiver. But there are some actions that need to check whether should start an activity or not and we are implementing this in BroadcastReceiver. I'm thinking about starting a transparent activity to handle this (although this looks like a workaround). Thank you for your comments.
👍 1
r

Rahul Rawat

11/09/2021, 9:15 AM
Glad I could help. Please remember to finish the activity when your redirection or work is done so the activity doesn’t remain on backstack or become a ghost which prevents user’s interaction with their screen.
👍 1
m

My Nguyen

11/09/2021, 9:16 AM
Certainly. Thanks for your remind.
FYI: I found out the exact reason. It's not because of the restrictions on when apps can start activities when the app is running in the background from Android 10. It's because of the Notification trampoline restrictions on Android 12. Details here: https://developer.android.com/about/versions/12/behavior-changes-12#notification-trampolines
r

Rahul Rawat

11/10/2021, 5:58 AM
So it seems my way has become the official way then 😁
m

My Nguyen

11/10/2021, 6:30 AM
Yes. Their suggest is the same as your 😁
View count: 9