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

    Saket Poddar

    05/22/2020, 8:26 AM
    What happens to tasks enqueued in Workermanager and app faces process death ? Will those tasks survive and later when app is relaunched will it be started or how it is ?
    a
    • 2
    • 1
  • a

    ahmad

    05/22/2020, 9:54 AM
    Hello 👋 Do you have a good example on how can I make Jenkins calculate the APK size and methods count changes for each build? I checked diffuse, but was looking if someone tried to integrate it before with Jenkins or have another options
    a
    g
    j
    • 4
    • 13
  • s

    Shreyas Patil

    05/22/2020, 6:38 PM
    https://link.medium.com/sm7NfjtoH6
    👍 5
    i
    f
    • 3
    • 2
  • j

    Joshua

    05/23/2020, 4:35 PM
    So I just implemented my drawer and all the menu-items inside of it. I'm able to navigate between my fragments through the menu-items, however, if im in fragment A and click on the menu-item that takes me to fragment A, another view will be created on top of it. So I'm able to create several fragments on top of each other. How can I solve this?
    r
    a
    • 3
    • 2
  • d

    Deepti M

    05/24/2020, 8:02 AM
    Hi Everyone, I have one old Android project, written in Java and recently created a library using Kotlin and all latest features. When I imported it in Java Android project, I am stuck with this error... java.lang.RuntimeException: Unable to start activity ComponentInfo{MainActivity}: android.view.InflateException: Binary XML file line #29: Error inflating class com.google.android.material.navigation.NavigationView Can't I use Kotlin library in Java project?
    f
    • 2
    • 11
  • a

    Archie

    05/24/2020, 3:35 PM
    Hi Guys, I was wondering whether anyone has been testing coroutine with Espresso? it is a common pattern with MVVM to do something like:
    class AViewModel() : ViewModel() {
        val liveData = MutableLiveData<SomeData>()
        ...
        fun doSomething() {
            viewModelScope.launch {
                //... do some long operation ....
                liveData.value = resultOfLongOperation
            }
        }
    }
    and observe the live data in Fragment or Activity like:
    ...
        val viewModel by viewModels<AViewModel> { ... }
        ...
        fun onViewCreate(...) {
            button.setOnclickListener {
                viewModel.doSomething()
            }
            
            viewModel.liveData.observe(viewLifecycle, Observer { result ->
            textView.text = result
        })
        }
    ...
    I was wondering how to do UI test for the Code above. Since the
    doSomething()
    takes a while to complete, my
    Espresso
    test is failing. Can anyone share how they do their test? Thank you very much.
    f
    • 2
    • 8
  • d

    Deepti M

    05/25/2020, 12:59 AM
    Hi Everyone, I want to execute sub-query using LiveData observer mechanism. Is it possible? How? Thanks for help, in advance!
    s
    • 2
    • 1
  • d

    Denys

    05/25/2020, 7:55 AM
    Hello everyone. I use the Room as database in my app. In my DAO, I use Flow as the return type so that the user interface updates automatically when the underlying data changes. The problem is that if an error occurs and I process it with the catch operator, I will never receive an update again in Flow. I don’t know how I can keep an active subscription to the database in case of an error. I would be grateful for any advice
    g
    • 2
    • 1
  • k

    Kaushik

    05/25/2020, 8:32 AM
    Hi, Any one help me how to fix this issue. Thanks in advance. Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void android.os.Parcelable.writeToParcel(android.os.Parcel, int)' on a null object reference This is happening in kotlin model class
    s
    h
    • 3
    • 5
  • g

    Geert

    05/25/2020, 8:48 AM
    Can someone help me with custom notification sounds? Do i have to recreate a new channel every time I the user changes it in my app? Currently I have to uninstall the app to get the new sound working. That doesn’t seem correctly?
    :stackoverflow: 1
    l
    • 2
    • 3
  • r

    ReddyTintaya

    05/25/2020, 11:38 PM
    Hi, i start a picker with this code. i want to get the path for then read that file and send it to my backend with multipart using this line, in a xiaomi device works fine, there the path looks like this "/storage/emulated/0/Download/images.jpeg"
    File(photoPath).asRequestBody("image/jpg".toMediaTypeOrNull())
    //REQUEST_CODE_PICK_IMAGE = 101
    Intent(Intent.ACTION_PICK).also {
        it.type = "*/*"
        val mimeTypes = arrayOf("image/jpeg", "image/png", "application/pdf")
        it.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
        startActivityForResult(it, REQUEST_CODE_PICK_IMAGE)
    }
    and then i use this
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK) {
            when (requestCode) {
                REQUEST_CODE_PICK_IMAGE -> {
                    selectedImageUri = data?.data
                    Log.i("develop", "data: ... $data")
                    image.setImageURI(selectedImageUri)
                    homeViewModel.selectedImageUri = selectedImageUri?.lastPathSegment.toString()
                }
            }
        }
    }
    a
    • 2
    • 5
  • o

    Orhan Tozan

    05/26/2020, 9:41 AM
    What is the industrial standard in identifying errors in production, without letting the user's app crash?
    p
    s
    +2
    • 5
    • 11
  • m

    Merseyside

    05/26/2020, 1:16 PM
    Hey! I got a question about databinding. I got the library which I can implement as project or from maven. With Maven it works well, but when I do it as project than binding stops to generate BindingImpl classes which xml files contain custom adapters from library. Why it may happens? Also I can navigate to source code of adapters from xml.
    f
    • 2
    • 1
  • r

    Remon Shehata

    05/26/2020, 3:38 PM
    https://stackoverflow.com/questions/62025918/how-to-structure-firebase-database-to-ger-results-like-relational-databases
    c
    • 2
    • 2
  • d

    dewildte

    05/27/2020, 3:34 AM
    How do I access a file (.md for example) in a kotlin module/library? The file is located in the module.
    :stackoverflow: 5
    o
    n
    • 3
    • 3
  • e

    Elyes

    05/27/2020, 12:41 PM
    I accidentally clicked on an option along the lines of “supress all warnings for unused binding adapters” from the quick action menu (ctrl/opt + enter). How do I undo that ?
    o
    • 2
    • 3
  • a

    Archie

    05/27/2020, 2:41 PM
    Guys, can I ask a question. I have a RecyclerView, with a ViewHolder which has a View with Button and TextView. I want to simulate a click on the Button but I dont know how. Can anyone guide me?
    o
    • 2
    • 1
  • s

    Slackbot

    05/27/2020, 3:27 PM
    This message was deleted.
    g
    a
    • 3
    • 2
  • m

    Mauricio Hernandez

    05/27/2020, 5:21 PM
    Hello @everyone,When taking a photo on a Samsung I get the following error :
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.securitas.aviation.satt/com.auxo.satt.main.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.auxo.satt.main.fragment.MainFragment: could not find Fragment constructor
    s
    • 2
    • 2
  • s

    Steve

    05/27/2020, 6:43 PM
    Is there an easy way to limit a DatePicker to only allowing Month and Year selection, or would it be easier to implement my own?
    :google: 1
    b
    • 2
    • 8
  • w

    william

    05/27/2020, 7:23 PM
    If I use
    *::class.java.name
    in my code, and I have proguard/r8 set up for that class to obfuscate it, the return value of that code would be the obfuscated version too?
    h
    • 2
    • 1
  • b

    Brady Aiello

    05/27/2020, 9:38 PM
    Will next week's livestream be available to watch immediately after it's over? https://developer.android.com/android11
    s
    • 2
    • 1
  • r

    Remon Shehata

    05/27/2020, 11:40 PM
    it doesn't seem right to do the db query in the view
    a
    • 2
    • 6
  • k

    Karan Sharma

    05/28/2020, 6:14 AM
    @here is there any performance difference between DataBinding / ViewBinding and Kotlin Synthetics ?
    b
    g
    b
    • 4
    • 15
  • m

    Mohamed Ibrahim

    05/28/2020, 11:32 AM
    hello there, I just want to know if there’s a server rendering solution for Android, like getting json describe the ui and a generator in android to do that, I know about compose but I need a production ready solution
    a
    l
    +2
    • 5
    • 13
  • t

    T

    05/28/2020, 12:41 PM
    I want to return the string form of the Json response. The error I get is "Expected a string but was BEGIN_OBJECT at path$"
    private const val BASE_URL = "<https://newsapi.org/v2/>"
    private const val API_KEY = "1234"
    
    private val moshi = Moshi.Builder()
        .add(KotlinJsonAdapterFactory())
        .build()
    
    private val retrofit = Retrofit.Builder()
        .addConverterFactory(MoshiConverterFactory.create())
        .baseUrl(BASE_URL)
        .build()
    
    interface NewsApiService {
        @GET("top-headlines?country=us&apiKey=${API_KEY}")
        fun getProperties():
                Call<String>
    }
    
    object NewsApi {
        val retrofitService : NewsApiService by lazy {
            retrofit.create(NewsApiService::class.java) }
    }
    class NewsViewModel : ViewModel() {
    
        // The internal MutableLiveData String that stores the most recent response
        private val _response = MutableLiveData<String>()
    
        // The external immutable LiveData for the response String
        val response: LiveData<String>
            get() = _response
    
        /**
         * Call getNewsData() on init so we can display status immediately.
         */
        init {
            getNewsData()
        }
    
        /**
         * Sets the value of the status LiveData to the News API status.
         */
        private fun getNewsData() {
    
            _response.value = NewsApi.retrofitService.getProperties().enqueue(
                object: Callback<String> {
                    override fun onFailure(call: Call<String>, t: Throwable){
                        _response.value = "Failure: " + t.message
                    }
    
                    override fun onResponse(call: Call<String>, response: Response<String>) {
                       _response.value = response.body()
                    }
                }).toString()
        }
    }
    a
    j
    • 3
    • 8
  • a

    aipok

    05/28/2020, 1:58 PM
    I’m seeing following issue with LiveData and
    viewLifecycleOwner.lifecycleScope.launch
    If I’m trying to update live data in my VM from
    .value
    other fragments with same VM do not get it from observer. I have to use
    postValue
    and in that case it delivered properly. Does anyone know why could it be? Previously I have been using
    uiScope
    uiScope = CoroutineScope(Dispatchers.Main + job)
    to launch coroutines inside my fragments and it was working fine with
    .value
    but after I switched to
    viewLifecycleOwner.lifecycleScope
    it is not anymore.
    h
    s
    • 3
    • 5
  • e

    Elka

    05/28/2020, 3:00 PM
    Any idea on how to get the screen height on Android... Trying to use
    Display.getMetrics
    but the API is not consistent... On some devices the method includes the status bar height while on others it gives only the usable area of the screen...
    a
    o
    • 3
    • 6
  • k

    Klaus

    05/28/2020, 8:37 PM
    How can I achieve that this
    DividerItemDecoration
    is only shown between sections and not between rows?
    a
    • 2
    • 2
  • s

    Slackbot

    05/28/2020, 8:48 PM
    This message was deleted.
    s
    • 2
    • 1
Powered by Linen
Title
s

Slackbot

05/28/2020, 8:48 PM
This message was deleted.
s

Saurabh

05/29/2020, 4:40 AM
As far as I can understand you want a carousel. There are a lot of libraries for this. But I reckon you can achieve this using a recycler view and a pager snap helper
View count: 2