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

    Felipe Tavares

    07/23/2019, 2:15 PM
    Hello... If i want to build a modular architecture app, when I create a new module... I need to select android library?
    m
    j
    d
    • 4
    • 17
  • m

    moizest89

    07/23/2019, 3:27 PM
    Hello Guys!! Someone has experience using Realm with
    sealed
    class like values? I’ve found examples with
    Enum
    class but not with sealed 😕
    h
    d
    z
    • 4
    • 15
  • v

    vapoyan

    07/24/2019, 6:43 AM
    Hello everyone, Can you please share what kind of Extensions (Android specific) are you using in your projects to make your day to day life easier and writing code shorter 🙂
    t
    y
    +3
    • 6
    • 12
  • d

    dakinne

    07/24/2019, 9:30 AM
    I want to use a event bus in my project. I use kotlin and coroutines but I don't use Rx. Can you recommend me what event bus to use or a good approach?
    g
    r
    r
    • 4
    • 22
  • g

    Gilles Braun

    07/24/2019, 12:14 PM
    Hey guys, this is not really kotlin specific but I have a weird issue with a shared viewmodel between an activity and fragment: The activity's observer is only executed once, whereas the fragment's observer is executed on every update. Any ideas why this might be?
    r
    g
    • 3
    • 24
  • s

    Stefan

    07/24/2019, 12:24 PM
    Hi. I'm having some problems with using listpreference.setValue or setIndexValue. None of the methods that I need to alter the values of a listpreference programmatically doesn't seem to be available. My class extends Preferencefragmentcompat Thanks Stefan
    t
    • 2
    • 4
  • k

    Katie Levy

    07/24/2019, 10:33 PM
    Here's my latest story on Open Sourcing my Android Kotlin Library at Intuit! http://bit.ly/2LEBiFG
    👍 4
    i
    • 2
    • 1
  • j

    Joaquim Ley

    07/25/2019, 1:16 PM
    Hello I’ve been :google: for some time now and SO and couldn’t really find a reason for this: I have Room returning
    Flowable<List<Model>>
    — This
    Model
    is a data class (hence I would assume
    equals()
    works as expected). But for some reason I get multiple notifications on a db change (I’ve mapped it with
    distinctUntilChanged()
    ) This question [1] is addressing the same but I’ve had no success with the suggestions, and the accepted answer is referencing exactly
    Object.equals
    , I’ve also tried [2] using the suggestion as the distinct predicate, but with no success Thank you in advance for your time --- [1] https://stackoverflow.com/questions/48585491/room-flowable-invokes-multiple-times [2] https://stackoverflow.com/questions/35272761/how-to-compare-two-arrays-in-kotlin/48769967#48769967
    j
    • 2
    • 2
  • s

    Slackbot

    07/25/2019, 10:33 PM
    This message was deleted.
    j
    • 2
    • 1
  • m

    matt tighe

    07/25/2019, 11:32 PM
    is it possible to use sealed classes as types for fields of room entities? something like
    sealed class Animal
    object Dog : Animal()
    object Cat : Animal()
    
    @Entity
    data class Person(
        val name: String
        val favoriteTypeOfAnimal: Animal
    )
    writing a type converter doesn’t seem to do it
    m
    j
    • 3
    • 10
  • s

    Santosh Sharma

    07/26/2019, 7:22 AM
    Can you please help me to build phone app where I'll be able to recognise weather my phone call was received or aborted ?
    👎 9
    t
    p
    • 3
    • 2
  • s

    Slackbot

    07/26/2019, 10:16 AM
    This message was deleted.
    r
    c
    +2
    • 5
    • 5
  • i

    Ive Vasiljevic

    07/26/2019, 8:54 PM
    Does anyone have an example of how to use
    DialogFragment
    with Navigation Component. I am aware that only two months ago Android introduced support for DialogFragments with Navigation Component, but if anyone has done it successfully please provide an example. Thank you!
    v
    • 2
    • 2
  • t

    tseisel

    07/27/2019, 3:40 PM
    As the
    Observer
    interface for
    LiveData
    only has one
    observe
    function, why should we write
    Observer { ... }
    and not directly a lambda ? Also, wouldn't it be nice if the parameter of the
    Observer
    lambda would take the nullability of the
    T
    value from LiveData into account ?
    val nonNullable: LiveData<String> = ...
    nonNullable.observe(this) { value: String -> ... }
    val nullable: LiveData<String?> = ...
    nullable.observe(this) { value: String? -> ... }
    m
    • 2
    • 1
  • a

    Adam Powell

    07/27/2019, 4:11 PM
    https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary?hl=en#livedata has some examples
    👍 1
    l
    • 2
    • 1
  • j

    jw

    07/28/2019, 1:24 AM
    i have no idea. i'm like 15% of the SQL Delight team.
    a
    • 2
    • 2
  • a

    andrew

    07/28/2019, 2:14 AM
    The persistence is for stuff like session management, listing experiences (events), card tokens, bank tokens, friends, etc
    k
    • 2
    • 3
  • a

    ashwini

    07/28/2019, 8:08 AM
    I am facing a weird issue while unit testing Coroutines. There are two tests on the class, when run individually, they both pass and when I run the complete test class, one fails with assertion error. I am using
    MainCoroutineRule
    to use the
    TestCoroutineScope
    and relying on the latest Coroutine Testing Library Here is the test :
    @ExperimentalCoroutinesApi
        @Test
        fun testHomeIsLoadedWithShowsAndFavorites() {
            runBlocking {
                // Stubbing network and repository calls
                whenever(tvMazeApi.getCurrentSchedule("US", currentDate))
                    .thenReturn(getFakeEpisodeList())
                whenever(favoriteShowsRepository.allFavoriteShowIds())
                    .thenReturn(arrayListOf(1, 2))
            }
    
            mainCoroutineRule.runBlockingTest {
                // call home viewmodel
                homeViewModel.onScreenCreated()
                // Check if loader is shown
                assertThat(LiveDataTestUtil.getValue(homeViewModel.getHomeViewState())).isEqualTo(Loading)
                // Observe on home view state live data
                val homeViewState = LiveDataTestUtil.getValue(homeViewModel.getHomeViewState())
                // Check for success data
                assertThat(homeViewState is Success).isTrue()
                val homeViewData = (homeViewState as Success).homeViewData
                assertThat(homeViewData.episodes).isNotEmpty()
                // compare the response with fake list
                assertThat(homeViewData.episodes).hasSize(getFakeEpisodeList().size)
                // compare the data and also order
                assertThat(homeViewData.episodes).containsExactlyElementsIn(getFakeEpisodeViewDataList(true)).inOrder()
            }
        }
    The other test is almost similar which tests for Shows without favorites. I am trying to test
    HomeViewModel
    method as:
    fun onScreenCreated() {
            homeViewStateLiveData.value = Loading
            val coroutineExceptionHandler = CoroutineExceptionHandler { _, exception ->
                onError(exception)
            }
    
            viewModelScope.launch(coroutineExceptionHandler) {
                // Get shows from network and favorites from room db on background thread
                val favoriteShowsWithFavorites = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
                    val favoriteShowIds = favoriteShowsRepository.allFavoriteShowIds()
                    val episodes = tvMazeApi.getCurrentSchedule(COUNTRY_US, currentDate)
                    getShowsWithFavorites(episodes, favoriteShowIds)
                }
                // Return the combined result on main thread
                withContext(Dispatchers.Main) {
                    onSuccess(favoriteShowsWithFavorites)
                }
            }
        }
    I cannot find the actual cause of why the tests if run separatly are passing and when the complete class is tested, one of them is failing. Pls help if I am missing something
    l
    r
    • 3
    • 2
  • m

    Magnus W

    07/28/2019, 3:42 PM
    Hi! Do I need to use a MediaStore + permission READ_EXTERNAL_STORAGE to read a file from disk?
    val fixedPath = "/storage/emulated/0/AnkiDroid/collection.media/主人_B_zh.mp3"
    val myURI = Uri.fromFile(File(fixedPath)
    I'm trying to load a file to my mediaPlayer directly using this URI, bit I get permission denied Reference here: https://developer.android.com/preview/privacy/scoped-storage#opt-out-of-filtered-view
    :stackoverflow: 3
    :google: 1
    • 1
    • 1
  • l

    locke

    07/29/2019, 11:27 PM
    Anyone have any idea why a BindingAdapter is being recognized at compile time as available, but at runtime during view inflation, the adapter is not called? It's as if the Xml parser is just skipping right over those attributes
    m
    w
    • 3
    • 11
  • m

    Magnus W

    07/30/2019, 6:51 PM
    Is it possible to track what exact permission I am missing if I get the following error?
    java.lang.RuntimeException: Unable to start activity ComponentInfo{cafe.gophers.mynavigationapplication/cafe.gophers.mynavigationapplication.MainActivity}: java.lang.SecurityException: Permission not granted for: CardContentProvider.query /notes (cafe.gophers.mynavigationapplication)
    I have added the permissions I found on github for CardContentProvider, but that didn't work
    b
    • 2
    • 5
  • i

    Ive Vasiljevic

    07/31/2019, 9:26 AM
    Is it possible to restart Navigation graph so that when application is restored it starts from the start of the graph?
    j
    j
    +2
    • 5
    • 5
  • n

    Nikolai

    08/01/2019, 4:06 PM
    Hi everyone, I have a question about Android, but not related to Kotlin (sorry). 1. Is it a good practice to use multiple fragments on one activity? 2. Is where any rules, best practices when to choose layout inside fragment, and when to move it to separate fragment?
    a
    n
    • 3
    • 6
  • n

    Nir Golan

    08/01/2019, 6:38 PM
    Hey all, I need some help with koin. I want to inject context. Any help on how to do it? Can't find anything helpfully. Thanks
    m
    l
    +2
    • 5
    • 5
  • g

    girafferson

    08/01/2019, 10:12 PM
    I am using the navigation components and I'm trying to only use deep links to navigate in my app. One requirement is that if I navigate to a fragment (single act arch) I need to see the deep link that started the fragment. Another requirement is that the deep link is pulled from FirebaseRemoteConfig so I can't use explicit deep link. When I use navigate(uri, navOptions) I get an empty bundle as args and no KEY_DEEP_LINK_INTENT. No new intent in activity. Any help is appreciated
    r
    m
    • 3
    • 3
  • d

    Daniel Rodak

    08/02/2019, 6:40 AM
    I'm passing function as a parameter, this function comes from dagger injected interface. Works as expected but I'm struggling with adding tests using
    Mockito
    . When I want to verify that a method with function as parameter was called, it always complains about strange difference. The difference is in the first brackets, it's like contex of the test method. Using
    Captors
    didn't help, because I mock the injected interface it will return null
    Untitled
    r
    • 2
    • 3
  • a

    andrew

    08/04/2019, 3:21 PM
    Hello, I have a nav controller that I want to be disposable in a sense. I have a DialogFragment that is a bit complex, but not complex enough for an Activity. A NavController would be a perfect fit for handling some of its subviews. However, a it seems an instance of the graph is stored somehow because when I inflate the layout again, I get an exception
    a
    • 2
    • 4
  • j

    james

    08/05/2019, 1:16 AM
    does anyone know if it's possible to pass a function reference using databinding? specifically, I wanted to do something like this:
    android:text="@{viewModel.message(context::getString)}"
    where my
    viewModel
    class has a function like:
    fun message(getStringFunc: (Int) -> String)
    g
    j
    • 3
    • 8
  • s

    Slackbot

    08/05/2019, 7:02 AM
    This message was deleted.
    g
    h
    • 3
    • 2
  • r

    Riushin

    08/05/2019, 2:42 PM
    Hello 👋 At the moment, I’m working on a webview and I’m trying to put a token header. However, during any redirection, this token no longer appears. During the first call, the token is present in the header but when I enter the functions shouldOverrideUrlLoading and shouldInterceptRequest the header is empty. An idea of how to do this? I already try several solutions on the net, including the one to add the header by hand using okhttp when calling shouldInterceptRequest but nothing ...
    :google: 2
    :stackoverflow: 3
    p
    • 2
    • 4
Powered by Linen
Title
r

Riushin

08/05/2019, 2:42 PM
Hello 👋 At the moment, I’m working on a webview and I’m trying to put a token header. However, during any redirection, this token no longer appears. During the first call, the token is present in the header but when I enter the functions shouldOverrideUrlLoading and shouldInterceptRequest the header is empty. An idea of how to do this? I already try several solutions on the net, including the one to add the header by hand using okhttp when calling shouldInterceptRequest but nothing ...
:google: 2
:stackoverflow: 3
p

Pablichjenkov

08/05/2019, 6:43 PM
Are you using Android CookieManager? I had an issue like that using the Android Cookie Manager with Chrome version 71. But it got fixed in 72.
Headers are saved by url, if the redirection points to a different url they are not kept.
r

Riushin

08/06/2019, 8:46 AM
When there is a redirect in the webview, cookies are not kept?
p

Pablichjenkov

08/06/2019, 2:59 PM
I remember back in time from a WebView login integration I did for a company,I had a similar problem. My headers were empty in all the WebView Callback events. Reasons can be multiple. Now, regarding your question. Headers are not handled by the system, the system only handle a couple of basic headers like
userAgent
. You have to send the headers manually when you call the load() method. The only type of headers the system handles for you is the Cookies. If you use the CookieManager you can inject your Cookies there and it will take care of the rest. The benefits is that the same CookieManager is a Singleton used by Chrome App too. So you can re-use Cookies-Login Tokens between your app and Chrome seamlessly. Cookies are saved by url hostname. If the redirect url has a different hostname, then the original request Cookies are not sent. With the rest of the header types am not sure whats the behavior but is probably the same as the cookies. Maybe for security reasons they do not transfer the original Url headers to the redirected Url. In such a case you would have to do it on your own.
View count: 3