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

    Mikołaj Karwowski

    01/29/2020, 1:03 PM
    Anybody knows why I can't use a declared dependency when creating a x-platform Kotlin library? Even though I add it to commonMain, it's visible only in androidMain :/
    sourceSets["commonMain"].dependencies {
            implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
            implementation ("org.java-websocket:Java-WebSocket:1.4.0")
        }
    Java-WebSocket seems to me just a java library, so shouldn't it be available in common library part?
    m
    2 replies · 2 participants
  • l

    luke

    01/30/2020, 12:27 AM
    For some reason in my
    Service
    I'm unable to get a
    String
    from resources, tried in
    onStartCommand()
    onCreate()
    and
    onDestroy()
    , does anyone have any ideas?
    t
    j
    22 replies · 3 participants
  • c

    crankup

    01/30/2020, 9:14 AM
    Hello everyone, I am learning Kotlin and I have a question about enum vs sealed classes. Should I use sealed when my enum constants needs diffferent constructors ? Should I always use sealed classes no matter what ...
    👋 1
    s
    e
    +2
    9 replies · 5 participants
  • h

    Hackdiod

    01/31/2020, 11:27 AM
    Hello! Do you now jetpack compose channel or use stackoverflow for questions? Unfortunately I did't find good tutorial about all compose items and have some problem.
    m
    2 replies · 2 participants
  • i

    iex

    01/31/2020, 4:17 PM
    I've this code in a `ViewModel`:
    private val testSingle = Single.just("item1")
    
    private val foo = testPublishSubject.startWith(testSingle.toObservable().doOnNext {
        Timber.i(">>> single on next: $it")
    }).doOnNext {
        Timber.i(">>> PS on next: $it")
    }
    
    fun onSomeEvent() {
        testPublishSubject.onNext("item2")
    }
    So it's a
    PublishSubject
    that gets initialized with a
    Single
    . On certain event, I push a new value to the subject. So far so good! The problem: I navigate to next screen and navigate back. Then the subject is reset to the initial
    Single
    value ("item1"). Why? The
    ViewModel
    is not reinitialized.
    s
    h
    28 replies · 3 participants
  • o

    Olenyov Kirill

    01/31/2020, 4:46 PM
    Hi, does anybody know any alternate AndroidTV frameworks or library except Leanback? Something written in Kotlin with modern approaches? Because Leanback looks like old, weird and with strange “presenter” system..
    s
    1 reply · 2 participants
  • b

    Brian Dilley

    01/31/2020, 6:27 PM
    I thought Android TV was deprecated
    🤣 2
    a
    t
    4 replies · 3 participants
  • t

    Travis Griggs

    01/31/2020, 9:44 PM
    I'm porting an iOS app to Kotlin/Android. Is there a parallel to CLLocationCoordinate2D in Android? I found Location, but that's more analagous to iOS's CLLocation (which is a coordinate plus bearing and other things). I found LatLng which looked like it might be what I wanted until I noticed that was in androidx.car. 😞 Number DDG searches aren't really turning up anything. Maybe there's a class name that's just obvious, I've missed it? Or a third party library?
    z
    b
    4 replies · 3 participants
  • j

    Jabez Magomere

    02/03/2020, 1:32 PM
    I'm working on a codebase with both Java and Kotlin code, i introduced Kotlin coroutines to help in running background tasks, however i have a function in my repository marked with the keyword suspend and i call it from an Intent Service that is written in java to sync local db with remote. However i can only call a suspend function from another suspend function or a coroutine builder. I three options in mind: Option 1 Use GlobalScope.launch(Dispatchers.IO) on the function so that i can call it from the Intent Service. However GloablScope is not highly recommended in the android context. Option 2 Make my repository extend Coroutine Scope, create a public function called onCleared that cancels job, then call this function when the service onDestroyed method is called or when the view model onCleared method is called. This option is to try and cancel any running operations. Option 3 Use the viewmodel scope to launch the coroutine in the repository, then call the viewmodel from the service, however the viewmodel should only be limited to an activity or fragment. Option 4 Refactor the intent service to Kotlin and use coroutines
    s
    n
    5 replies · 3 participants
  • m

    Mohammed Suleman

    02/03/2020, 3:57 PM
    Hello Can anyone Suggest me good Android book which i can use it from scratch.
    d
    a
    +4
    10 replies · 7 participants
  • o

    Ofir Bar

    02/04/2020, 9:54 AM
    Hey guys, I am really confused. I am fetching some variable programatically from my dimens.xml. When on evaluating expression on the android studio debugger, I get “ResourceNotFoundException” However, the variable does get its value and works fine. Any idea why do I get that exception when debugging?
    :google: 1
    :stackoverflow: 1
    j
    d
    4 replies · 3 participants
  • b

    bhatnagarm

    02/04/2020, 11:02 AM
    Hey guys, Can main app module and library module have different product flavors. If yes then how?
    :google: 2
    :stackoverflow: 2
    s
    d
    15 replies · 3 participants
  • d

    dambakk

    02/04/2020, 12:25 PM
    What’s the latest on “How to accessibility” (especially in these
    ConstraintLayout
    days)? Any recommended guides, documentations, tutorials, talks?
    d
    3 replies · 2 participants
  • g

    gert.claeskens

    02/04/2020, 12:50 PM
    When trying to start an RecognizerIntent I get the following exception in the logs, which causes the intent to finish immediately
    :stackoverflow: 3
    d
    1 reply · 2 participants
  • j

    John

    02/04/2020, 1:51 PM
    Does anyone have a way to instantiate a DialogFragment with an lambda?
    :google: 1
    s
    6 replies · 2 participants
  • a

    adheus

    02/04/2020, 5:00 PM
    Has anyone here used the cloudtestingscreenshotter_lib.aar to take screenshots during an instrumentation test? It’s not working here. (Reference: https://firebase.google.com/docs/test-lab/android/test-screenshots#view_screenshots) Failing with the following message:
    E/cloud_screenshotter: Exception taking screenshot: <http://java.io|java.io>.FileNotFoundException: /sdcard/screenshots/UnknownTestClass-unknownTestMethod-test-1.jpg (No such file or directory)
    :google: 2
    :stackoverflow: 1
    w
    1 reply · 2 participants
  • n

    Nikola Milovic

    02/05/2020, 9:32 AM
    Hey guys any working plate recognition libraries available online? Or any service that could accept images being sent to them. Anything really. Need it for a school project. I dont care how good it is, just need anything. I couldnt find a working project nor library. Everything is either outdated or not working properly.. Any link or help will be appreciated! Thanks!
    :google: 3
    s
    1 reply · 2 participants
  • o

    Ofir Bar

    02/05/2020, 9:46 AM
    Is there a Kotlin way to avoid the code duplication marked here? (Those are syntactic views references)
    s
    m
    +2
    20 replies · 5 participants
  • j

    Javier

    02/05/2020, 11:35 AM
    From here: https://developer.android.com/topic/libraries/view-binding
    private var _binding: ResultProfileBinding? = null
    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!
    
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = ResultProfileBinding.inflate(inflater, container, false)
        val view = binding.root
        return view
    }
    
    override fun onDestroyView() {
        _binding = null
    }
    binding
    cannot be null never? If for some reason I want to get the context via
    binding.root.context
    and the fragment is not attached, I can not get a NPE? @jw
    a
    s
    8 replies · 3 participants
  • s

    Saket Poddar

    02/05/2020, 2:20 PM
    I am confused about a scenario where there are couple of activities put together, but I want to have single viewmodel for each of the activities instead of keeping each activity with their individual viewmodel. What are pros and cons with this approach?
    :google: 1
    g
    m
    +1
    6 replies · 4 participants
  • g

    Gabriel Brandao

    02/05/2020, 5:41 PM
    Does anyone know how to create a WebView with Jetpack Compose?
    :google: 1
    a
    1 reply · 2 participants
  • i

    iex

    02/06/2020, 6:25 AM
    any library recommendation for lightweight date operations (like "days between 2 dates")? I'd prefer something that doesn't add extensions to numbers
    :google: 1
    :stackoverflow: 1
    k
    f
    +2
    8 replies · 5 participants
  • s

    Sergio C.

    02/06/2020, 8:21 AM
    Anyone knows how to invoke a method before a method that has a custom annotation? I want to run some code before this method with a custom annotation. How can we do this in kotlin?
    :stackoverflow: 1
    f
    a
    3 replies · 3 participants
  • m

    Maku Mazakpe

    02/06/2020, 8:48 AM
    hey guys, So... im want to add permissions into my app? My question is... where should i add them? In the main activity?, a helper class? what?!... Thanks in advance.
    n
    1 reply · 2 participants
  • l

    lawlorslaw

    02/06/2020, 9:14 AM
    i have a marker interface
    interface RoomModel
    and an entity that implements this interface
    @Entity(tableName = "ContentAuthorModule")
    ContentAuthorModule : RoomModel {}
    now if i have a
    List<RoomModel>
    how do i check if its a
    List<ContentAuthorModule>
    I tried to do
    roomModels is List<ContentAuthorModule>
    override fun saveRoomModels(roomModels: List<RoomModel>) {
        when(roomModels) {
            is List<ContentAuthorModule> ->
                contentAuthorModuleDao.insertAll(roomModels)
        }
    }
    but it gives my a syntax error that says
    Cannot check for instance of erased type : List<ContentAuthorModule>
    is there another way to do this?
    a
    2 replies · 2 participants
  • b

    Basil

    02/06/2020, 7:03 PM
    I'm writing Espresso UI tests for my Android app. The trouble is I can't figure out how to iterate through my
    ChipGroup
    and perform a click on individual `Chip`s. Any ideas?
    :stackoverflow: 5
    w
    1 reply · 2 participants
  • l

    lawlorslaw

    02/06/2020, 11:27 PM
    if i have a variable
    clazz
    that is a
    KClassImpl
    how would i check if that is of type
    FooBar
    i tried this
    clazz.java.isInstance(FooBar::class.java)
    but that always returns false
    t
    1 reply · 2 participants
  • r

    Remy Benza

    02/07/2020, 12:08 PM
    which has quite some code to support multiple back stacks.
    :google: 2
    :stackoverflow: 2
    r
    f
    8 replies · 3 participants
  • r

    Remy Benza

    02/07/2020, 4:11 PM
    I'm using navigation components in a large complex app. It provides an extension function
    by navGraphs()
    which lets you scope 1 viewmodel to all the screens inside a specific navgraph. Normally you would have 1 viewmodel for each screen. Besides the benefits (easy state/data sharing between all your screens) what is a potential drawback of this approach?
    d
    z
    4 replies · 3 participants
  • s

    STAYER

    02/07/2020, 7:22 PM
    Hello guys! Can someone explain me why extension function not working with Log class or Crashlytics?
    fun Log.dd(msg: String? = "null", tag: String = "test1") = Log.d(tag, msg)
    r
    r
    +1
    8 replies · 4 participants
Powered by Linen
Title
s

STAYER

02/07/2020, 7:22 PM
Hello guys! Can someone explain me why extension function not working with Log class or Crashlytics?
fun Log.dd(msg: String? = "null", tag: String = "test1") = Log.d(tag, msg)
r

rkeazor

02/07/2020, 7:27 PM
They dont work with statics
👍 1
s

STAYER

02/07/2020, 7:46 PM
Thanks! They really have private constructor with no chance to create instance.
r

Rajkumar Singh

02/08/2020, 2:03 AM
did you mean msg: String? = null
or msg: String? = "null"
s

STAYER

02/10/2020, 9:40 AM
@Rajkumar Singh, it's just example. I realize 2 extensions, this:
fun Any.logE(msg: String, tr: Throwable? = null, tag: String = "test1") = when (tr) {
    null -> Log.e(tag, msg)
    else -> Log.e(tag, msg, tr)
}
And this:
fun Any.crashlyticsLog(tr: Throwable, msg: String): Unit {
    logE(msg, tr)
    Crashlytics.log(msg)
    Crashlytics.logException(tr)
}
So i can log errors to Logcat and report to crashlytics in one line. For example:
try {
    //Do something
} catch(e: Exception) {
    crashlyticsLog(e, "some info")
}
p

pavi2410

03/16/2020, 3:11 AM
@STAYER you need to take a look into Timber library. It's built for that
👍 1
s

STAYER

03/16/2020, 3:18 AM
@pavi2410 yep, i use Timber in new project, and it is nice)
p

pavi2410

03/16/2020, 3:18 AM
Great to know that
View count: 2