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

    Tin Tran

    09/01/2021, 7:47 AM
    Hi! Does anyone know why job2() is not running? Am I doing something wrong?
    class MyViewModel:ViewModel() {
       private val job = SupervisorJob()
       private val scope = CoroutineScope(<http://Dispatcher.IO|Dispatcher.IO> + job)
    
       fun test() {
           viewModelScope.launch {
               job1()
               job.cancelAndJoin()
               scope.launch {
                   job2()
               }
          }
      }
    }
    j
    j
    • 3
    • 9
  • t

    Tower Guidev2

    09/01/2021, 9:44 AM
    Hi, I have a strange Kotlin serialisation issue in my current Android application
    h
    e
    • 3
    • 5
  • l

    Lilly

    09/01/2021, 1:09 PM
    Can someone gie me a hint what is missing:
    val router: Router<Route> = rememberSaveable {
    	Router(Route.Status).apply { isSingleTop = true } // using apply does not work here
    }
    As far as I set
    apply
    , android studio complains:
    Required: Router<Dashboard.Route>
    Found: Router<Dashboard.Route.Status>
    Route
    is a sealed class, signature of
    Router
    is:
    class Router<T : Any>(private val backStack: List<T>) : RouterActions<T>
    j
    • 2
    • 6
  • s

    Sololo

    09/01/2021, 1:57 PM
    /Users/sololo/Library/Android/sdk/build-tools/30.0.2/aapt p -f -M ./app/src/main/AndroidManifest.xml -I /Users/sololo/Library/Android/sdk/platforms/android-29/android.jar -S ./app/src/main/res -J ./app -m
    • 1
    • 2
  • c

    codeslubber

    09/01/2021, 2:33 PM
    I have the Monterey Beta installed on an M1 laptop, the GA of Android Studio works fine, the Canary 10 build crashes immediately?
    h
    • 2
    • 1
  • s

    Sam

    09/01/2021, 8:30 PM
    I realise this isn't directly Kotlin related but I'm starting to tear my hair out. Can anyone point me in the right direction to get swagger codegen working with Moshi annotations? The only solution I'm finding is the Yelp plugin which doesn't support the latest OpenApi version 😞
    :not-kotlin: 1
    l
    c
    • 3
    • 4
  • a

    adjpd

    09/02/2021, 12:10 AM
    I want to use Retrofit's API but I want it to use kotlin `Flow`s. I've searched around a little but found nothing particularly elegant. Currently my API returns a
    Call<String>
    . I'd like it to return a
    Flow<String>
    with the least amount of boilerplate possible. How are you all doing it?
    j
    h
    • 3
    • 6
  • s

    Slackbot

    09/02/2021, 8:35 AM
    This message was deleted.
    :not-kotlin: 1
    a
    • 2
    • 1
  • t

    The Monster

    09/03/2021, 3:23 AM
    Hey guys when I code like this, it makes my app crashes because of stackoverflow error at LazyImpl kotlin. Is it illegal to access the variable catFacts like this?
    class CatFactsViewModel : ViewModel() {
    private val catFacts: MutableLiveData<List<String>> by lazy {
    MutableLiveData<List<String>>().also {
    loadCatFacts()
    }
    }
    fun getCatFacts(): LiveData<List<String>> {
    return catFacts
    }
    private fun loadCatFacts() {
    // Do an asynchronous operation to fetch cat facts.
    catFacts.value = listOf("fact 1", "fact 2")
    }
    }
    h
    m
    • 3
    • 7
  • h

    Hovhannes

    09/03/2021, 10:09 AM
    Hello, I've question. What is the best practice to pass a data from activity to a non activity class in MVVM and without using SharedPreferences?
    :stackoverflow: 2
    👍 1
    :not-kotlin: 3
    k
    • 2
    • 1
  • h

    Hovhannes

    09/03/2021, 1:34 PM
    Hello, I've a question. When I click the button, encrypted's value changes, but for body isn't changed. Retrofit always saves previous values of encrypted. Is it depend on Retrofit? If yes, how can I clear caches? class RemoteDataSource @Inject constructor() { companion object { var string: String?=null fun setEncr(string: String){ this.string=string } fun getEncr():String{ return this.string!! } } private fun getRetrofitClient( context: Context? = null): OkHttpClient { val authenticator:Authenticator?=null val encryp= getEncr() val body = "{\r\n\"Data\":\"${encryp}\"\r\n}" .toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) return OkHttpClient.Builder() .cache(null) .addInterceptor { chain -> chain.proceed(chain.request().newBuilder().also { it.addHeader("Accept", "application/json") it.method("POST", body) }.build()) }.also { client -> authenticator?.let { client.authenticator(it) } if (BuildConfig.DEBUG) { val logging = HttpLoggingInterceptor() logging.setLevel(HttpLoggingInterceptor.Level.BODY) client.addInterceptor(logging) } }.build() } } in MainActivity binding.buttonLogin.setOnClickListener { val clientId = binding.edittxtClientId.text.toString().trim() encrypted = encrypt(clientId, publicKey) setStr(encrypted) viewModel.loginResponse.observe(this, Observer { when (it) { is Resource.Success -> { ..... } }
    :not-kotlin: 3
    l
    • 2
    • 1
  • r

    Rita Okonkwo

    09/03/2021, 2:14 PM
    Hi everyone! So I’m looking to use navigation components in my androidApp module. I have included the dependencies for navigation and plugin for safe args in the android app build.gradle.kts file and I have concluded the class path for safe args in my top level build.gradle.kts file. However I am unable to navigate with safe args because the Directions class name of my fragment is an unresolved reference. Would really appreciate any help I can get with this. Thanks!
    k
    • 2
    • 3
  • a

    adjpd

    09/04/2021, 4:41 PM
    I'm struggling to understand why I should use
    StateFlow
    instead of
    LiveData
    . From what I can tell it's main benefits are 1) It's a Kotlin language feature rather than an Android library and 2) you can use intermediate "flow" operations on it rather than use a get()ter method to manipulate the data. That's pretty much it, right?
    c
    a
    +3
    • 6
    • 14
  • c

    codeslubber

    09/04/2021, 10:09 PM
    So here is an android/kotlin question we discussed in our mob yesterday. We have a chat channel and we show a since label (how long since the message was sent). Of course this should update right? 5 minutes from now it should say ‘5 minutes ago,’ 10 minutes ago 10. Right? So the question is this: the whole idea in LiveData to trigger observers on sets called on the Viewmodel property. Thing is of course, this is a computed field. I did not find anything about this, which surprised me. What would be the best approach (it’s computed of course as a time interval from posted to now).
    e
    j
    • 3
    • 2
  • a

    Ahmed Sellami

    09/05/2021, 7:47 PM
    Started a series about Jetpack Compose animations. That's the first article: https://developersbreach.com/add-item-animation-compose/
    c
    • 2
    • 1
  • t

    The Monster

    09/06/2021, 1:31 AM
    Hey the doc says
    runBlocking
    blocks the current thread, so why is
    Hello
    still printed first? Shouldn't it blocks for 3 secs and prints
    Hello
    at the end?
    Untitled.cpp
    s
    j
    • 3
    • 4
  • h

    Hovhannes

    09/06/2021, 6:39 AM
    Hello, I've a question. When I click the button, encrypted's value changes, but for body isn't changed. Retrofit always saves previous values of encrypted. Is it depend on Retrofit? If yes, how can I clear caches?
    class RemoteDataSource @Inject constructor() {
            companion object {
               var string: String?=null
    
                fun setEncr(string: String){
                    this.string=string
                }
    
                fun getEncr():String{
                    return this.string!!
                }
           }
    
           private fun getRetrofitClient( context: Context? = null): OkHttpClient {
            val authenticator:Authenticator?=null
    
            val encryp= getEncr()
            val  body = "{\r\n\"Data\":\"${encryp}\"\r\n}"
                    .toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
    
    
            return OkHttpClient.Builder()
                .cache(null)
                .addInterceptor { chain ->
                    chain.proceed(chain.request().newBuilder().also {
                        it.addHeader("Accept", "application/json")
                        it.method("POST", body)
                    }.build())
                }.also { client ->
                    authenticator?.let { client.authenticator(it) }
                    if (BuildConfig.DEBUG) {
                        val logging = HttpLoggingInterceptor()
                        logging.setLevel(HttpLoggingInterceptor.Level.BODY)
                        client.addInterceptor(logging)
                    }
                }.build()
         }
     }
    in MainActivity
    binding.buttonLogin.setOnClickListener {
        val clientId = binding.edittxtClientId.text.toString().trim()
        encrypted = encrypt(clientId, publicKey)
        setStr(encrypted)
        viewModel.loginResponse.observe(this, Observer {
    
                    when (it) {
                        is Resource.Success -> {
                        .....
        }
    }
    :not-kotlin: 7
    l
    • 2
    • 1
  • r

    Rajput Art Studio

    09/06/2021, 1:32 PM
    Hello Respected seniours Can you please help me how to generate a excel file programmatically in android kotlin Used so libraries but facing dependency issues. Thank you
    h
    l
    • 3
    • 5
  • s

    Sam Marz

    09/06/2021, 10:51 PM
    Hi! is it possible to know how many times a
    Composable
    function has been called to
    Recomposition
    ?
    w
    v
    • 3
    • 3
  • o

    Orhan Tozan

    09/07/2021, 12:07 PM
    Is KSP production ready, or are folks still using Kapt mostly? Looking at Room's doc, showing an option to use KSP in your dependency list for the room compiler
    y
    t
    • 3
    • 6
  • d

    Daniel Brauer

    09/07/2021, 12:13 PM
    Hi, I’m new to Kotlin and Android Studio, and I’m having trouble getting AS to resolve references to libraries from code. This issue seems to be specific to KMM projects, whereas a regular Android Activity sees them right away.
    ⬆️ 1
    c
    g
    • 3
    • 14
  • n

    nilTheDev

    09/07/2021, 2:23 PM
    Which view group is used here to create this kind of layout? (This is a screenshot from WhatsApp status feature). I couldn't find anything regrading this. Maybe because I don't know the right keyword for this. My best guess is that it is a fragment that doesn't take up the whole screen. And this feature is using navigation. The paused screen in the background is probably from the backstack. Please enlighten me.
    :not-kotlin: 3
    c
    k
    • 3
    • 3
  • s

    Slackbot

    09/07/2021, 7:37 PM
    This message was deleted.
    💩 1
    :not-kotlin: 2
    👎 4
    l
    • 2
    • 2
  • s

    Spikey Sanju

    09/08/2021, 12:37 AM
    Android studio crashes after I update from
    BigSur
    to
    Monterey
    . I'm using
    M1 Apple Sillicon
    Machine. Whenever I try to open android studio it's showing the crash log. Crash log in Thread ℹ️
    :not-kotlin: 4
    c
    h
    • 3
    • 3
  • s

    Shobana Velmurugan

    09/08/2021, 5:09 AM
    Hello friends, Google play store my app is not listed in Samsung Galaxy S20 Plus Ultra mobile. That mobile screen resolution is 3200x1440 and the Dpi value is 525. But Samsung Galaxy S10 it's working fine. here is the code i added in manifest file. this not supported for an Tablet devices.
    <compatible-screens>
        <screen android:screenDensity="ldpi" android:screenSize="small" />
        <screen android:screenDensity="mdpi" android:screenSize="small" />
        <screen android:screenDensity="hdpi" android:screenSize="small" />
        <screen android:screenDensity="xhdpi" android:screenSize="small" />
        <screen android:screenDensity="420" android:screenSize="small" />
        <screen android:screenDensity="480" android:screenSize="small" />
        <screen android:screenDensity="560" android:screenSize="small" />
        <screen android:screenDensity="640" android:screenSize="small" />
        <!--Normal-->
        <screen android:screenDensity="ldpi" android:screenSize="normal" />
        <screen android:screenDensity="mdpi" android:screenSize="normal" />
        <screen android:screenDensity="hdpi" android:screenSize="normal" />
        <screen android:screenDensity="xhdpi" android:screenSize="normal" />
        <screen android:screenDensity="420" android:screenSize="normal" />
        <screen android:screenDensity="480" android:screenSize="normal" />
        <screen android:screenDensity="560" android:screenSize="normal" />
        <screen android:screenDensity="640" android:screenSize="normal" />
        <!--Large-->
        <screen android:screenDensity="ldpi" android:screenSize="large" />
        <screen android:screenDensity="mdpi" android:screenSize="large" />
        <screen android:screenDensity="hdpi" android:screenSize="large" />
        <screen android:screenDensity="xhdpi" android:screenSize="large" />
        <screen android:screenDensity="420" android:screenSize="large" />
        <screen android:screenDensity="480" android:screenSize="large" />
        <screen android:screenDensity="560" android:screenSize="large" />
        <screen android:screenDensity="640" android:screenSize="large" />
    </compatible-screens>
    Does anyone help me? with what I did wrong?
    :not-kotlin: 5
    u
    k
    • 3
    • 4
  • a

    Atul P Kaushik

    09/08/2021, 10:44 AM
    hi , anyone know....on how to enable ..mouse wheel scroll for scrollview in android ..ie my app connected to a monitor via secondary display..and scrolling is not happening via mouse scroll
    :not-kotlin: 4
    n
    • 2
    • 7
  • j

    Johnjake Talledo

    09/08/2021, 1:38 PM
    Hello guys I have a unit test that requires to access or read the assets I tried
    InstrumentationRegistry.getInstrumentation().targetContext
    but its seems to not working. I am guessing its incorrect
    context
    @RunWith(RobolectricTestRunner::class)
    @Config(manifest=Config.NONE)
    class JobOrderUnitTest {
        @get:Rule
        var instantTaskExecutorRule= InstantTaskExecutorRule()
    
        @get:Rule
        var coroutineRule = MainCoroutineRule()
    
        lateinit var viewModel : JobOrderViewModel
    
        private val context = InstrumentationRegistry.getInstrumentation().targetContext
    
        @Before
        fun setUp() {
            viewModel = JobOrderViewModel(JobOrderRepository())
        }
    
        @Test
        fun `fetch data from mock server`() {
    
        }
    
        @ExperimentalCoroutinesApi
        @Test
        fun `This collect data from repository`() {
            coroutineRule.runBlockingTest {
                viewModel.fetchJobOrder(context)
                viewModel.jobOrder.collect { list ->
                    assert(list == listOf<Order>())
                }
            }
        }
    }
    :not-kotlin: 1
    • 1
    • 1
  • o

    Orhan Tozan

    09/08/2021, 2:48 PM
    Will kotlin-android-extensions be removed? If so, is there a planned date?
    🙏 1
    a
    • 2
    • 2
  • a

    appleobject

    09/08/2021, 9:40 PM
    I updated to the latest android studio "arctic" and whenever my gradle build it returns error with reason unknown
    :not-kotlin: 1
    👀 1
    k
    • 2
    • 2
  • k

    K Merle

    09/09/2021, 10:11 AM
    How to use abstract class ViewModel with hiltViewModel?
    :not-kotlin: 4
    v
    • 2
    • 2
Powered by Linen
Title
k

K Merle

09/09/2021, 10:11 AM
How to use abstract class ViewModel with hiltViewModel?
:not-kotlin: 4
v

Viktor Petrovski

09/09/2021, 5:30 PM
What exactly are you trying to achieve? If you want to have an abstract
ViewModel
you should use hilt to get an instance of your actual
ViewModel
who extends the abstract
ViewModel
. You can’t have object from an
abstract
class.
👌 1
k

K Merle

09/10/2021, 5:50 AM
Was able to achieve it with:
val viewModel: Interface = hiltViewModel<InterfaceImpl>()
View count: 5