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

    quocdev

    01/02/2018, 6:05 AM
    hi everyone, happy new year I has been learning the Android, So could you suggest me the Architecture MVVM of Kotlin (demo or app) used the RxJava2+ Databinding Thanks so much !
    g
    n
    • 3
    • 13
  • s

    sabag.ronen

    01/02/2018, 8:11 AM
    Hi all, every time that I’m adding new instrumentation tests file with kotlin and try to run the test, Android studio try to run it as Juint test is anyone face this issue? in order to overcome this issue I’m editing the configuration to be instrumentation but i prefer that the studio will know it for me 🙂
    a
    • 2
    • 3
  • m

    mingkangpan

    01/02/2018, 9:39 AM
    guys why doesn't lint apply when using
    map.getOrDefault()
    which is only supported if JDK 8 is used? also here is an article about that: https://proandroiddev.com/kotlin-youve-broken-my-heart-ea0e8f991b70
    g
    l
    • 3
    • 4
  • r

    Ruthvik

    01/02/2018, 11:28 AM
    Hi guys. Any good tutorials to learn kotlin with android ??
    g
    • 2
    • 2
  • d

    david.bilik

    01/02/2018, 11:34 AM
    @Sudhir Singh Khanger
    mutableListOf
    is a constructor of mutable lists,
    MutableList
    is type
    s
    r
    • 3
    • 3
  • k

    kirillrakhman

    01/02/2018, 3:15 PM
    Have you seen
    Warning: stripped invalid locals information from 1 method.
    Some warnings are typically a sign of using an outdated Java toolchain. To fix, recompile the source with an updated toolchain.
    when compiling with D8?
    l
    • 2
    • 8
  • d

    Daniel

    01/02/2018, 9:09 PM
    Hello Guys I have a rather strange problem. When I write an androidTest in Kotlin and try to run it it asks me to choose between two run configurations: Unit Test and Instrumented Test. This is not the case with java where it autodetects the instrumented run config. Does anybody also has this problem?
    a
    • 2
    • 3
  • l

    louiscad

    01/03/2018, 9:03 AM
    Hi, does anyone know of a way to dynamically generate AndroidManifest elements at compile time? I'm thinking of a way to make a kapt library automatically register some generated components in the manifest
    m
    m
    n
    • 4
    • 4
  • s

    smartynk

    01/03/2018, 6:14 PM
    Not strictly Kotlin-related, but for folks who wrangle a lot of source-sets in Android Studio 3.0+, where different productFlavors represent quite different apps to the user, have you had any “lessons-learned” or best-practise moments?
    :stackoverflow: 5
    b
    • 2
    • 2
  • g

    gitanshu

    01/03/2018, 6:32 PM
    @jw tried EAP. works fine. Thanks 😄
    k
    • 2
    • 3
  • t

    Thiago

    01/03/2018, 7:20 PM
    I pasted the file into the class, but it did not convert directly. Is there any option that should be enabled?
    a
    s
    k
    • 4
    • 12
  • j

    Jitendra

    01/04/2018, 3:06 AM
    How to detect if my activity has been obscured
    :stackoverflow: 10
    t
    • 2
    • 1
  • f

    Fré Dumazy

    01/05/2018, 11:10 AM
    Having some issues with lateinit property and the recreation of a killed Activity and its fragments... I'm initializing this property in
    Activity.onCreate()
    , then adding the
    Fragment
    , which uses this property in its
    onCreate()
    When the Activity is recreated after being killed, it first creates its fragments again, causing
    Fragment.onCreate()
    to be called before the initialization in
    Activity.onCreate()
    . Is there any way to fix this, or is my design wrong? I've posted this on SO as well: https://stackoverflow.com/questions/48112311/lateinit-property-not-initialized-when-activity-is-re-created
    h
    • 2
    • 2
  • r

    raghuramjampala

    01/05/2018, 11:29 AM
    Hi what static analysis tools are you using for kotlin on Android.. detekt?, ktlint or anything else
    a
    • 2
    • 1
  • n

    nickk

    01/05/2018, 12:19 PM
    Android Studio 3.0.1 started to produced warnings like this one:
    Warning: Stripped invalid locals information from 1 method.
    
    Methods with invalid locals information:
      java.lang.Object kotlin.collections.SlidingWindowKt$windowedIterator$1.doResume(java.lang.Object, java.lang.Throwable)
    Some warnings are typically a sign of using an outdated Java toolchain. To fix, recompile the source with an updated toolchain.
    Cannot figure out what changed…
    g
    k
    • 3
    • 3
  • y

    yaakov

    01/05/2018, 5:50 PM
    Is it better to use a kotlin coroutine or just to use the thread API in Android? I've been thinking of what is the "smart" way to prevent my grabcut() call from breaking the UI thread.
    c
    d
    +2
    • 5
    • 6
  • l

    louiscad

    01/09/2018, 9:09 PM
    Hi all, what is the best name for a function that shows an indefinite Snackbar according to you?
    snackForever(…)
    ,
    snackForLife(…)
    ,
    snackOfYourLife(…)
    , or something else? (:thread-please: )
    r
    a
    m
    • 4
    • 3
  • l

    louiscad

    01/09/2018, 9:37 PM
    @evan The name of my library is "Splitties". It means all features are split in small, mostly independent modules, to keep the dex count as low as practically doable. I try to do so without increasing dex size by inlining big methods without lambdas. So I think I'm on the right path for small footprint, but I want to do the right naming choices and support the API for the long term
    a
    • 2
    • 30
  • s

    Sudhir Singh Khanger

    01/10/2018, 1:02 PM
    Can a MutableList have items of two different (object) type? If not what are my alternatives?
    a
    p
    c
    • 4
    • 4
  • a

    Alexander Khyzhun

    01/10/2018, 1:05 PM
    Guys, please, use threads for any question instead of simple message 🐵 🙈 🙉
    l
    • 2
    • 1
  • t

    tateisu

    01/10/2018, 3:16 PM
    I think it would be useful if the kotlin converter replaces 「if(!TextUtils.isEmpty(s))」 with 「 if(s?.isNotEmpty()==true)」. (also inverted conditions are 「if(TextUtils.isEmpty(s))」 with 「if( s?.isEmpty()!=false) 」.) Because the latter performs a null check and safe cast.
    👍 1
    a
    • 2
    • 2
  • p

    Paul Woitaschek

    01/10/2018, 6:14 PM
    I have hundrets of
    !!
    because of that ^^
    😔 1
    k
    • 2
    • 1
  • r

    radzio

    01/10/2018, 8:35 PM
    Hi everyone! I want to use Kotlin extension function to remove
    if(Build.VERSION.SDK_INT)
    from my code. I've created this:
    inline fun <T> T.applyForOreoOrAbove(block: T.() -> Unit): T {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        block()
      }
      return this
    }
    Unfortunately, Android Lint still complains that call requires... Is it a bug in the Lint or am I doing something wrong?
    l
    j
    • 3
    • 6
  • b

    brokenpipe

    01/11/2018, 1:01 PM
    Hi, is there any known issue with Espresso tests written in Kotlin recognized as UnitTests instead of Android Instrumented Test? I cannot run any Kotlin written test...
    👍 1
    l
    • 2
    • 2
  • j

    joshc

    01/11/2018, 8:03 PM
    @josefrichter Yes, support library, plus use minSdk androidmanifest.xml and/or build.gradle. ref: https://developer.android.com/guide/topics/manifest/uses-sdk-element.html
    g
    • 2
    • 1
  • l

    louiscad

    01/11/2018, 9:31 PM
    Hi all, what would you choose?
    inline fun View.onClick(crossinline l: (v: View) -> Unit) = setOnClickListener { l(it) }
    
    inline fun View.onClick(noinline l: (v: View) -> Unit) = setOnClickListener(l)
    The first one is optimized but doesn't gives you a proper stacktrace for the
    l
    lambda in case you want it, if you get an exception for example. The second one generates 2 classes instead of one, and has 3 methods calls instead of one when a click strikes, but you see it all in the stacktrace, with the exception source. Note that the second one still produces meaningful method and class names. Just the line number is plain wrong and misleading (not hard to figure out you can't trust it).
    MainActivity$onCreate$$inlined$onClick$1.onClick
    1️⃣ 2
    w
    d
    • 3
    • 3
  • s

    sodiqoladeni

    01/12/2018, 2:50 AM
    https://kotlinlang.slack.com/archives/C0B8MA7FA/p1515725365000144
    k
    • 2
    • 1
  • k

    khoatd191

    01/12/2018, 9:53 AM
    I update TestRule but seem like it doesn’t work well
    b
    r
    • 3
    • 3
  • a

    Ayden

    01/12/2018, 10:21 AM
    What is the
    view as Button
    means?
    v
    m
    b
    • 4
    • 16
  • l

    Lukas Anda

    01/12/2018, 7:52 PM
    Hi guys, I have a question. Let's say I have a View Holder for RecyclerView and I have 2 layouts with the same views and same names, just different sizes of views. How can I use synthetic with kotlin ?
    b
    j
    b
    • 4
    • 18
Powered by Linen
Title
l

Lukas Anda

01/12/2018, 7:52 PM
Hi guys, I have a question. Let's say I have a View Holder for RecyclerView and I have 2 layouts with the same views and same names, just different sizes of views. How can I use synthetic with kotlin ?
b

bachhuberdesign

01/12/2018, 8:36 PM
Great question, this is one of the few edge cases where I think findViewById() would actually be a better option. Would love to get other opinions on this.
l

Lukas Anda

01/12/2018, 9:22 PM
Maybe the creator or @jw could help us out here ? Do you know what would be cool ? If we could override those views in this style
j

jw

01/12/2018, 9:23 PM
I've never used the synthetic properties and I find them to be the wrong solution to the larger problem
l

Lukas Anda

01/12/2018, 9:24 PM
Okay, so how do you propose solving this case ? Dagger or is there something else ?
j

jw

01/12/2018, 9:24 PM
Sounds like
findViewById
solves the problem
l

Lukas Anda

01/12/2018, 9:25 PM
Well, okay. I thought there are other ways of solving this. But thank you for your answer
b

boy

01/12/2018, 9:32 PM
@jw I would like to know why synthetic is a wrong way to go. I loved Butterknife, but not needing to use any annotation at all is really making my life more fun. I even have a generic ViewHolder that takes a view and I don’t have to findViewById or inject anything. It makes coding so much easier. And afaik it is just lazy-loading the views using
findViewById
You will probably make a good point that will make me stop using synthetic properties…so I migh (probably) regret this question 🤐
j

jw

01/12/2018, 9:35 PM
Databinding has a superior approach as it generates a type per layout (including across resource configurations) with properties for all contained views. This means no need for a magic cache behind the scenes and no need for magic imports. It also optimizes the lookup requiring only a single traversal over the view tree instead of one per view. When a view is only included in one configuration but the other it's marked as nullable. When you use different types across configurations the property reflects the common supertype.
➕ 2
Unfortunately Databinding also includes databinding which I don't really like.
☝️ 3
😂 5
😀
b

boy

01/12/2018, 9:36 PM
😆 yep, not a fan of databinding either
It is probably more efficient, but in real case scenario, I rather have easier coding than needing to write more code (variable declarations in XML and stuff, just don’t like it)
the performance penalty is probably not interesting
because that is what I guess you’re pointing at, that it costs performance
j

jw

01/12/2018, 9:42 PM
Right. Which is why i'd like the layout codegen part of databinding to be separate somehow. Because I'd rather do like
val layout = LayoutName(context)
layout.name.text = "hey"
etc.
👍 2
b

boy

01/12/2018, 9:43 PM
that would be great!
Hope you are able to make this happen 😉
View count: 2