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

    Ch8n

    05/23/2021, 7:37 PM
    Hi is anyone having any good resources to read about the internals of the jetpack viewmodel? i was checking some logs and observed onClear is getting called before onDestory of Activity, I was expecting it to be called after onDestroy as per the diagram in docs
    2021-05-24 00:41:39.235 22590-22590/com.example.myapp D/******* on stop >>>>: ON-STOP
    2021-05-24 00:41:39.237 22590-22590/com.example.myapp D/******* on cleared  view-model>>>>: ON-CLEARED
    2021-05-24 00:41:39.238 22590-22590/com.example.myapp D/******* on destroy >>>>: ON-DESTROY
    z
    1 reply · 2 participants
  • j

    Jason

    05/24/2021, 7:11 AM
    Hello ! Does anyone know how to programmatically restart app in single Activity architecture?
    :stackoverflow: 3
    g
    n
    5 replies · 3 participants
  • s

    Sam

    05/24/2021, 8:24 AM
    Hello, Good morning everybody. Im curious about 2 solutions convert 
    dp
     to 
    px
    Solution 1:
    fun Int.dpToPx(context: Context): Int {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), context.resources.displayMetrics).toInt()
    }
    Solution 2:
    fun Int.dpToPx() = (Resources.getSystem().displayMetrics.density * this + 0.5f)
    so Which once is correct for multiple screen? Thanks.
    l
    e
    8 replies · 3 participants
  • c

    Clément Jean

    05/24/2021, 10:08 AM
    Hi guys, I'm new to the kotlinlang slack so I'm not sure if what I send is what I should send in this channel (if it's not please forgive me). I'm trying to put the following jetpack-compose code in a separate gradle module called
    ui_components
    (android library)
    /**
     * Display a vertical list of [OutlinedTextField]
     */
    @Composable
    fun Form(fields: List<FormField>) {
        LazyColumn(content = {
            items(fields) { item ->
                OutlinedTextField(
                    value = item.mutableState.value,
                    onValueChange = { item.mutableState.value = it },
                    label = { Text(text = stringResource(id = item.label)) },
                    isError = item.isError(item.mutableState.value)
                )
            }
        })
    }
    However, when I compile the logs show me the following error:
    e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'items' into
    local final fun androidx.compose.foundation.lazy.LazyListScope.<anonymous>(): kotlin.Unit defined in com.xxx.xxx.ui_components.Form
    {
            items(fields) { item ->
                OutlinedTextField(
                    value = item.mutableState.value,
                    onValueChange = { item.mutableState.value = it },
                    label = { Text(text = stringResource(id = item.label)) },
                    isError = item.isError(item.mutableState.value)
                )
            }
        }
    Am I doing something wrong here? Because individually the module compile (so no dependency missing, I guess) and without the dependency to
    ui_components
    the app compiles. Would be great if you can explain me, thanks in advance! 🙏
    o
    1 reply · 2 participants
  • s

    solidogen

    05/24/2021, 12:03 PM
    navigation component question: I have fragments A,B,C I want to have a shortcut of going from A to C, but also have a way to popup from C to B what is the recommended way to do this?
    r
    46 replies · 2 participants
  • d

    David Alford

    05/24/2021, 10:16 PM
    I just updated my app from kotlin-gradle-plugin:1.4.32 to 1.5.10. When I compiled, the following extension method no longer compiles. If I roll back to 1.4.32, it compiles again. (I've inlined some stuff to make it clearer so no need to point out the redundant lambdas. I just want to understand why it worked before, but doesn't now.) If I convert the property to a function, it also works (but i'd prefer to keep it a property). Code:
    val UByteArray.utf8:String
    	get() {
    		val index = this.indexOf(0u)
    		val cleaned = if (index == -1) {
    			{ this }()
    		}
    		else {
    			{ this.sliceArray(0 until index) }()
    		}
    		return cleaned.toByteArray().toString(Charsets.UTF_8)
    	}
    Error Message:
    com.android.tools.r8.errors.b: Field name '$this_<get-utf8>' cannot be represented in dex format.
    e
    16 replies · 2 participants
  • r

    Rishabh Deep Singh

    05/25/2021, 5:41 AM
    Currently we are using RxView to handle throttle clicks inside app and we have utility functions to subscribe on click listeners, we never unsubscribe from them. Is there an easy way to do so? or similar?
    fun throttledClick(
            targetView: View,
            completionMethod: () -> Unit,
            throttleWindow: Long = DOUBLE_CLICK_THROTTLE_WINDOW
        ) {
            RxView.clicks(targetView)
                .throttleFirst(throttleWindow, MILLISECONDS)
                .subscribe {
                    completionMethod.invoke()
                }
        }
    s
    2 replies · 2 participants
  • e

    Eugen Martynov

    05/25/2021, 8:55 AM
    Does kotlin REPL work for the JDK 9+?
    t
    3 replies · 2 participants
  • b

    Barry Fawthrop

    05/25/2021, 4:39 PM
    Hi all. I recently upgrade my app to support data binding. so no more findViewById. just binding.view. I now want to move to a MVVM using ViewModels, so that I can move to LiveData. not sure (1) do both MVVM and LiveData at the same time or separately? (2) How does one begin to implement ViewModel from the old XML findViewById/binding way of doing things? Thanks all
    :not-kotlin: 2
    d
    2 replies · 2 participants
  • s

    Slackbot

    05/25/2021, 6:47 PM
    This message was deleted.
    e
    1 reply · 2 participants
  • s

    Slackbot

    05/25/2021, 6:47 PM
    This message was deleted.
    e
    e
    +1
    7 replies · 4 participants
  • s

    Slackbot

    05/25/2021, 6:47 PM
    This message was deleted.
    e
    1 reply · 2 participants
  • t

    Tash

    05/25/2021, 11:45 PM
    Hi all! Has anyone ever used `LifecycleObserver`s for running
    suspend
    functions or collecting
    Flows
    via
    lifecycleOwner
    -> scope?
    :yes: 2
    a
    8 replies · 2 participants
  • k

    Klaas Kabini

    05/26/2021, 12:12 PM
    I am trying to extend the AppCompatSeekBar to draw labels below the tick marks (e.g. 0 20 40 60 80 100). I have overriden the onDraw method to draw the labels on the Canvas but the labels are not showing. Can someone look at the code snippet in this thread and tell me what is it that I may be doing wrong.
    1 reply · 1 participant
  • v

    Vitaliy Zarubin

    05/26/2021, 12:39 PM
    Tell me please. Is it possible to somehow connect the cache with the Room database so that the data is loaded at the start of the application. I want to have a list with data at the start. So far, there is only one idea - to make two lists. I think this is bad.
    2 replies · 1 participant
  • i

    Ink

    05/26/2021, 1:34 PM
    if (errorMessage != null) {
        if (model.iconEnd == null) {
            model.iconEnd = InputField.Icon.ERROR
        } else {
            if (model.iconEnd != InputField.Icon.ERROR)
                model.icon = InputField.Icon.ERROR
        }
    } else {
        if (model.iconEnd == InputField.Icon.ERROR) {
            model.iconEnd = null
        }
        if (model.icon == InputField.Icon.ERROR) {
            model.icon = null
        }
    }
    Is it possible to simpligy that code?
    e
    v
    4 replies · 3 participants
  • a

    Ahmed Mourad

    05/26/2021, 4:19 PM
    Hey everybody, What's the recommended approach for using Paging 3 and Room with Clean Architecture? Since the domain layer is Java or Kotlin only, my repository or usecases can't return a
    PagingSource
    and implementing it in the presentation layer is far from ideal.
    d
    a
    13 replies · 3 participants
  • z

    Zun

    05/26/2021, 4:40 PM
    I recently came across a simplified version of NetworkBoundResource. I was wondering how I could trigger a refresh (through user interaction, when pressing a button) if the flow fails and emits an error. Or is this inline function not the right approach?
    g
    1 reply · 2 participants
  • r

    Rupesh Singh

    05/26/2021, 6:03 PM
    Hey everybody, Can anyone please suggest me to work on an android app project that can impress my interviewers.( please help me...I'm not getting any ideas😣😣)
    z
    a
    +2
    6 replies · 5 participants
  • s

    Sam

    05/27/2021, 2:32 AM
    Hello, good morning everybody. I have implement 
    *Modular Android* App *Architecture*
     , so I would like to discuss these two solutions: • Problems: ◦ Target : 
    Module A
     send Event to show 
    Dialog
     on the screens and exclude a some screens. ◦ Features divided into separate modules. ◦ Example Requirement: Class SocketService in
    Module A
    get events from server in Application class , we use ActivityLifecycleCallbacks to get
    Current Activity
    , We do not display dialog on Search Screens, Map Screen, … etc ( 2 cases : several screens or large screens should not show dialog) • Solution 1: ◦ Create an Interface
    DoNotShowDialog
    in
    Common Module
    ◦ You will implement this interface to prevent to display
    Dialog
    in each modules/Activity class • Solution 2: ▪︎
    Module A
    use activity.javaClass.simpleName to compare with array of strings ▪︎ Example :
    arrayListOf("SearchActivity", "MapActivity").contains(this.javaClass.simpleName)
    Which solution will you choose? Thanks.
    2️⃣ 2
    1️⃣ 4
    p
    8 replies · 2 participants
  • p

    PhongBM

    05/27/2021, 4:09 AM
    Hi all, I have an issue with use both Dagger2 and Hilt in my project. I post this in Stackoverflow , please help me.
    c
    3 replies · 2 participants
  • c

    Christian Dräger

    05/27/2021, 6:25 AM
    hey, i am currently playing around with jetpack compose on android. since my experience with android is very beginner level (tbh i am a jvm backend developer trying to write my first android app 😄)  i am wondering how to avoid 
    android.os.NetworkOnMainThreadException
    i already figured out this is because i just call an http client (which is blocking) in the main activity (main/ui thread) as you can see on the screenshot. what do i need to do to make my http call with my client of choice work? stackoverflow was saying something about AsyncTasks but the answers has been very old and looked pretty different from my jetpack compose code 😄 I found solutions like: https://stackoverflow.com/a/13136668/10562333 that would just deactivate the restriction but that feels wrong to me. From what I understood so far I would need to do the call in a background thread instead of the main thread. Can I do this by wrapping my call in a coroutine and if so how? What would be the state of the art way to tackle this problem? (bearbeitet)
    f
    z
    +1
    17 replies · 4 participants
  • r

    Remon Shehata

    05/27/2021, 3:45 PM
    Hi, what is the difference between
    val obj : Object = Object()
    and
    val obj: Object get() = Object()
    ?
    z
    e
    5 replies · 3 participants
  • s

    Sudhir Singh Khanger

    05/27/2021, 4:06 PM
    I am trying to test an in-memory Room db which has suspend functions but the dao functions don't seem to be running in runBlocking. And tests fail.
    @RunWith(AndroidJUnit4::class)
    class SomeDaoTest {
    
      private lateinit var database: AppDatabase
      private lateinit var someDao: SomeDao
    
      @get:Rule
      var instantTaskExecutorRule = InstantTaskExecutorRule()
    
      @Before
      fun createDb() = runBlocking {
        val context = InstrumentationRegistry.getInstrumentation().targetContext
        database = Room
          .inMemoryDatabaseBuilder(context, AppDatabase::class.java)
          // needed to run @Transaction block
          .setTransactionExecutor(Executors.newSingleThreadExecutor())
          .build()
        someDao = database.someDao()
    
        someDao.insertAll(dummy1, dummy2)
      }
    
      @After
      fun closeDb() {
        database.close()
      }
    
      @Test
      fun testDeleteAll() = runBlocking {
          val someData = someDao.getData().getOrAwaitValue()
          someDao.deleteAll()
          assertEquals(0, someData.size)
        }
    Any help on how I should do it or how to troubleshoot it would be nice.
    c
    4 replies · 2 participants
  • j

    Jesus Cruz Victoria

    05/27/2021, 4:20 PM
    The option to *I*mport .JAR/.AAR Package from the New Module wizard has been removed.
    e
    1 reply · 2 participants
  • k

    Kevin Bowie

    05/28/2021, 2:09 AM
    Hello guys, any tips how to create Library like Picasso, Glide, Retrofit... so I can use it for other project ? thank you
    🤔 7
    c
    3 replies · 2 participants
  • a

    Aman Kapoor

    05/28/2021, 3:30 AM
    Hi. I have a question about resources in on-demand feature modules. Please check thread.
    :not-kotlin: 3
    g
    3 replies · 2 participants
  • s

    Sergio C.

    05/28/2021, 9:02 AM
    Hi everyone, How can I validate an input for a function with lint check? For instance if a function should accept only integers >= 0 how can I put a lint check in the parameter?
    z
    6 replies · 2 participants
  • v

    Vivek Modi

    05/28/2021, 10:23 AM
    Hey i am trying to add space between two words and append in a string builder. Showing in text view its not working and if check in logs it's showing perfectly. Does any one how to fix this?
    val list = mutableListOf(
            "1. Log in Google account\n",
            "2. Scroll to the page\n",
            "3. Tap disconnect from account to logout"
        )
        val content = StringBuilder()
        list.forEach{ string->
            content.append(string.replaceFirst(" " , "\t"))
        }
        System.out.print("string >> $content")
        list_string.text = content
    As you see it fine in logs
    1 reply · 1 participant
  • a

    Atchay Varma

    05/28/2021, 1:18 PM
    Hi guys I have made a Developer tool. Which is a search engine you can. There are 25+ Docs supported including Android, Flutter, React Native. For more info visit: https://www.producthunt.com/posts/devhuntrYou should use a common data source for
    z
    8 replies · 2 participants
Powered by Linen
Title
a

Atchay Varma

05/28/2021, 1:18 PM
Hi guys I have made a Developer tool. Which is a search engine you can. There are 25+ Docs supported including Android, Flutter, React Native. For more info visit: https://www.producthunt.com/posts/devhuntrYou should use a common data source for
z

Zun

05/28/2021, 1:30 PM
"We have gave him a brain. We used AI in our app whch will detect the typos and mistakes in your search and give you search suggestion so quicker.type anything we will correct it" ironic
a

Atchay Varma

05/28/2021, 1:33 PM
Give it a try and make it popular
z

Zun

05/28/2021, 1:34 PM
I pointed out various spelling mistakes/typos on your landing page. The irony is that your tool detects typos. How about using the tool on your own site?
a

Atchay Varma

05/28/2021, 1:35 PM
Oh I am in a rush
I will fix it
R u meaning our app name?
z

Zun

05/28/2021, 1:39 PM
I highlighted some mistakes. I suggest you let someone else write the landing page if English isn't your first language
a

Atchay Varma

05/28/2021, 1:40 PM
Ok fine
View count: 11