https://kotlinlang.org logo
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
  • s

    sarmad sohaib

    10/20/2022, 8:49 PM
    Hi I want to send data from
    BroadcastReciever()
    somewhere else, which can be
    viewModel
    ,
    repository
    , or
    fragment
    . I am not sure where to send data from receiver because i am newbie to MVVM architecture. I have three questions: 1. Where to send data from
    receiver
    ?
    ViewModel
    or
    repository
    ? 2. How to send data by not breaking the best practices and MVVM. 3. Should i use
    Coroutines
    in receiver? If yes, how? I am a beginner so please tell me if question is unclear. Code examples will help me a lot. I have tried almost everything from Internet and not a single solution was easy to understand. Thank you!
    p
    • 2
    • 4
  • z

    zt

    10/21/2022, 4:50 AM
    Is there a way to exclude a constructor property from being parcelized?
    e
    • 2
    • 1
  • p

    Per Jansson

    10/21/2022, 7:41 AM
    I have a pretty simple Android application built with Jetpack Compose, and I’m trying to use UIAutomator to perform a “opaque box” testing on it, simply visiting each page via the app menu. It is incredibly flaky and just once has it been able to perform the test to the end (so the selectors do work). I’m a using `testTag`:s, but I’ve also tried finding UI elements using text or description, even by clicking on a certain x, y coordinate, still the test is really flaky. This is kind of how it looks: Composable
    modifier = Modifier.testTag("HomeButton")
    Test
    // I've tried different ways of finding objects and different ways of waiting, but nothing seems to make the tests less flaky
    
    @Test
    fun verifyAllPages() {
        device.wait(Until.findObject(By.res("HomeButton")), DEFAULT_WAIT_TIME).click()
        device.wait(Until.findObject(By.res("MenuButton")), DEFAULT_WAIT_TIME).click()
        device.wait(Until.findObject(By.res("MenuItem_1")), DEFAULT_WAIT_TIME).click()
        ...
        ...
        ...
    }
    Questions that I have 1. Is this really how flaky UI Automator test are expected to be, or am I missing something? 2. What alternatives do I have if I want to write a test that visits all, or at least some, of the screens in the app? 3. How are people in general testing the Android apps? Coming from the web world it is common to build high level, “opaque box” tests using e.g. Cypress or Playwright.
    c
    • 2
    • 7
  • k

    KamilH

    10/21/2022, 8:33 AM
    How do you approach
    IdlingResources
    in app architecture that uses `Flow`s a lot? In my app I tried to implement similar solution to this however it doesn’t work well, because here we are waiting until job is not active anymore and it’s problematic when we, for example, observe changes in the database, because this kind of streams are not completing at all, which means we inform Espresso that app is busy all the time and tests are not resuming. Maybe it would be better to inform Espresso that the app is busy only when
    Flow
    is “processing” some value, however that doesn’t seem to be possible
    m
    • 2
    • 5
  • s

    Slackbot

    10/22/2022, 10:47 AM
    This message was deleted.
    v
    a
    • 3
    • 2
  • m

    Milo

    10/22/2022, 8:59 PM
    I have managed to send local notifications but How to send local notification same hour everyday?
    e
    • 2
    • 1
  • m

    Milo

    10/22/2022, 9:22 PM
    alarmManager.setExactAndAllowWhileIdle(
        AlarmManager.RTC_WAKEUP,
        time,
        pendingIntent
    )
  • m

    Milo

    10/22/2022, 9:22 PM
    val time = getTime()
  • m

    Milo

    10/22/2022, 9:22 PM
    private fun getTime(): Long {
        val minute = binding.timePicker.minute
        val hour = binding.timePicker.hour
        val day = binding.datePicker.dayOfMonth
        val month = binding.datePicker.month
        val year = binding.datePicker.year
    
        val calendar = Calendar.getInstance()
        calendar.set(year, month, day, hour, minute)
        return calendar.timeInMillis
    }
  • m

    Milo

    10/22/2022, 9:22 PM
    but How to send local notification same hour everyday?
  • s

    Sam Stone

    10/24/2022, 6:07 AM
    Are there any plans on Google's part to prefer Kotlin DSL Gradle over groovy to homogenize language usage? Compose is also a step towards that, away from XML.
  • c

    cedric akrou

    10/24/2022, 9:15 AM
    https://developer.android.com/events/dev-summit
  • c

    cedric akrou

    10/24/2022, 9:15 AM

    https://www.youtube.com/watch?v=Awi4J5-tbW4&ab_channel=AndroidDevelopers▾

  • d

    diego-gomez-olvera

    10/24/2022, 9:36 AM
    hello! I found an issue implementing a
    GestureDetector.OnGestureListener
    also seen in StackOverflow: Util API 32 the method could return
    null
    but since API 33 it's marked as
    @NonNull
    . There are possible workarounds for this: • A Java wrapper which doesn't enforces the nullability to keep it
    @Nullable
    • Remove
    override
    and suppress the warning None of them seems ideal, what do you use in your projects? I remember an Android blog post about the topic of migration but when previous versions could pass
    null
    are more problematic
  • t

    Tino

    10/24/2022, 5:46 PM
    Hi guys, does someone know where can I find kotlin/android gradle compatibility table? I'm using kotlin 1.7.10 in my KMM project
  • m

    Moritz

    10/24/2022, 7:38 PM
    Hello, i am very new at kotlin and i am wondering how i can add an second button (the function from the button not the button itself) to my MainActivity. I already have one but idk how to add a second one. Can someone maybe help me there? The code from the MainActivity: package com.example.myapplication import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.webkit.WebView import android.widget.Button class MainActivity2 : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main2) val VerButton = findViewById<Button>(R.id.button3) VerButton.setOnClickListener { val Intent = Intent(this, MainActivity::class.java) startActivity(Intent) } } }
    c
    • 2
    • 2
  • p

    Poyyamozhi Ramakrishnan

    10/25/2022, 2:43 PM
    Hi I'm developing an Android app where I have to display rich text like Text effects - Bold, Italic, Link, Images, Tables, Headings etc similar to Jira Android app. Attached image is from Jira web app where they have all text formats that I have mentioned above and I need to show them in android app. So if any one knows any library for this kindly let me know. Thanks in advance
    37a9f5ab-9243-4a63-b41b-4cd32888c45a.webp
    s
    • 2
    • 1
  • c

    cedric akrou

    10/25/2022, 2:55 PM

    https://youtu.be/CIZU_NNAZsA▾

  • s

    Sky

    10/25/2022, 8:29 PM
    How can I share image from Api url to other apps eg whatsapp etc. (Using Compose).. the answers in stackoverflow seems old,depreciated aren't working for me
    z
    • 2
    • 2
  • a

    Ashish Gautam

    10/27/2022, 12:10 PM
    Hello there! I working on project where I need to manage session, so whenever I found that my response give me error like 404 or 403 so I need to show popup/DailogueFragment what is the best way to setup globally, My project is multiple activity with multiple fragment based project, well I have tried this by making LogoutDialouge class which works fine when calling in activity, I think there is issue with context in fragment scenario. well I want other best approaches that you guys follow.
    g
    • 2
    • 5
  • m

    Milo

    10/27/2022, 8:42 PM
    How can I convert a string from hh🇲🇲ss to hours in double? string “00:20:00” expected result 0.333333333333333 string “01:00:00" expected result 1
    f
    • 2
    • 8
  • s

    Slackbot

    10/27/2022, 10:00 PM
    This message was deleted.
    f
    • 2
    • 1
  • z

    zt

    10/28/2022, 4:33 AM
    In my app I need to get some values from an API. Currently I'm just doing the API call inside my the init block of a class that I'm injecting using Koin. I'm doing the API call in a runBlocking call from kotlin coroutines but that does block the UI from loading until the variables are set. What would be the proper way of doing this so that it isn't blocking the UI and properly indicates to the user that it's loading?
    c
    g
    • 3
    • 4
  • t

    Tower Guidev2

    10/28/2022, 8:18 AM
    Hi i have an issue with Kotlin not allowing overriding functions to specify default values for its parameters my android application is using retrofit for api calls this means i have to specify network calls in an interface as follows:-
    z
    • 2
    • 10
  • a

    Ashu

    10/28/2022, 8:29 AM
    Hi In the new splash screen api, it there a way to show a full width image? Currently it clips image to a certain dimension. Android should not be forcing their in app design guidelines like this.
  • l

    Lee Delarm

    10/28/2022, 6:41 PM
    How do I call a suspend function (network call) when initializing my main activity? This is what I've got (from the tutorial) and it shows a blank page. I've even tried changing the return from the function to a simple string instead of making a call and get the same. There's no build or runtime red errors
    class MainActivity : ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContent {
                MyApplicationTheme {
                    Surface(
                        modifier = Modifier.fillMaxSize(),
                        color = MaterialTheme.colors.background
                    ) {
                        val scope = rememberCoroutineScope()
                        var text by remember { mutableStateOf("Loading") }
                        LaunchedEffect(true) {
                            scope.launch {
                                text = try {
                                    Greeting().greeting()
                                } catch (e: Exception) {
                                    e.localizedMessage ?: "error"
                                }
                            }
                        }
                        Greeting(text)
                    }
                }
            }
        }
    }
    z
    • 2
    • 4
  • l

    Lee Delarm

    10/28/2022, 6:42 PM
    The
    Greeting().greeting()
    should be returning a string of data
  • r

    Racka N

    10/29/2022, 10:55 AM
    Any ideas why I can't get my
    :benchmark
    module to run tests. Clicking on the test class opens a dialog to choose a module but none of my modules are being listed. If I change the build variant of my main
    :app
    module to
    debug
    I can see all my other module except the one for
    :benchmark
    . See the comments for my gradle setup. I'm on Android Studio Electric Eel Beta 03
    t
    • 2
    • 2
  • m

    Michael Job

    10/30/2022, 1:58 PM
    Why is there an extra hour here!?!
    fun getTimer(): String {
        val timeElapsed = LocalDateTime.ofInstant(Instant.ofEpochMilli(0), ZoneId.of("Europe/Paris"))
        val formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS").withZone(ZoneId.of("Europe/Paris"))
        return timeElapsed.format(formatter) //returns 01:00:00.000    //why 1 hour ???
    }
    b
    c
    a
    • 4
    • 4
  • a

    Asad Mukhtar

    10/30/2022, 7:17 PM
    I use this method to show the content above the status bar:
    fun Activity.setSystemPaddingForAppContent(view: View) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        ViewCompat.setOnApplyWindowInsetsListener(view) { view, windowInsets ->
            val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemGestures())
            // Apply the insets as padding to the view. Here we're setting all of the
            // dimensions, but apply as appropriate to your layout. You could also
            // update the views margin if more appropriate.
            view.updatePadding(insets.left, 0, insets.right, insets.bottom)
    
            // Return CONSUMED if we don't want the window insets to keep being passed
            // down to descendant views.
            WindowInsetsCompat.CONSUMED
        }
    }
    But the problem is that I have a simple activity due to the above function ScrollView, NestedScrollView not scroll even the content is scrollable.
Powered by Linen
Title
a

Asad Mukhtar

10/30/2022, 7:17 PM
I use this method to show the content above the status bar:
fun Activity.setSystemPaddingForAppContent(view: View) {
    WindowCompat.setDecorFitsSystemWindows(window, false)
    ViewCompat.setOnApplyWindowInsetsListener(view) { view, windowInsets ->
        val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemGestures())
        // Apply the insets as padding to the view. Here we're setting all of the
        // dimensions, but apply as appropriate to your layout. You could also
        // update the views margin if more appropriate.
        view.updatePadding(insets.left, 0, insets.right, insets.bottom)

        // Return CONSUMED if we don't want the window insets to keep being passed
        // down to descendant views.
        WindowInsetsCompat.CONSUMED
    }
}
But the problem is that I have a simple activity due to the above function ScrollView, NestedScrollView not scroll even the content is scrollable.
View count: 3