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

    hesam

    12/12/2019, 10:10 PM
    Hey guys I have a question. When I select an image from the Document, its uri looks like this:
    [<content://com.android.providers.media.documents/document/image%3A38>]
    However, when I take a photo and store it in MediaStore.Images, then its uri looks like this:
    [<content://media/external/images/media/51>]
    . Is there anyway that I get a uri like the first uri? [code in the comment]
    :stackoverflow: 6
    a
    • 2
    • 3
  • r

    Rishabh Harit

    12/13/2019, 8:19 AM
    Does any one know where are the change log for kotlin gradle plugin published. Specifically looking for this version in android studio 3.6 beta 5. https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin/1.3.61
    a
    • 2
    • 1
  • c

    carlos cdmp

    12/13/2019, 10:41 AM
    Has someone built a datatype adapter for retrofit? similar to the suspend native one but like
    fun getModel() : Either<Model, APIError>
    b
    • 2
    • 5
  • i

    Ive Vasiljevic

    12/13/2019, 12:22 PM
    Is it possible to use SharedPreferences as I would use Room library with liveData and emitSource()?
    r
    • 2
    • 1
  • s

    Subhrajyoti Sen

    12/13/2019, 1:13 PM
    I found a bug while converting some Java code to Kotlin on Android Studio. So should I report it on Studio's bug tracker or Kotlin?
    a
    • 2
    • 2
  • b

    Bryan Lee

    12/13/2019, 4:20 PM
    Jetpack Compose Question - Does anyone know if it's possible to use 3rd party views with compose yet? I've been trying to play around with Compose, but my app revolves around a custom map view, similar to google maps, and I can't figure out how to implement the view. I believe they mentioned in one of their conference videos that you would be able to use View binding for this type of situation - is that functionality available yet?
    l
    a
    • 3
    • 4
  • s

    Sebi Sheldin Sebastian

    12/14/2019, 1:15 PM
    Have a studio stable problem, and the #android-studio channel has only 10 people, not sure whether I'll get an answer there Android Studio 3.5.3 is freezing for me when I try to Inspect Code, it runs for a while and then freezes up, and it happens only on one of my projects so I can't create a minimum failure scenario, after it freezes up there is nothing I can do other than do a Force Quit, is there something I can do identify what might be causing this? But otherwise everything else works fine, building the code, installation, code cleanup works fine, its just the Inspect Code that freezes after running for a while and I have no logs or anything to try and identify why its happening, Further I have tried things like running a clean and build, and even invalidate and restart P.S It works fine on AS Canary 6 my bad it froze after a gradle sync and rebuild
    :google: 1
    :stackoverflow: 1
    d
    b
    • 3
    • 4
  • c

    Cake

    12/14/2019, 9:52 PM
    Hey guys, how do you handle the development of custom views in a architecture that uses MVVM or other architectural pattern.
    :google: 1
    r
    i
    • 3
    • 3
  • a

    Ayden

    12/15/2019, 4:25 AM
    Which method should I use is better?
    object Constant {
        URL = ""
    }
    
    OR
    
    class Constant {
        companion object {
            URL = ""
        }
    }
    p
    s
    • 3
    • 2
  • d

    deactivateduser

    12/15/2019, 9:23 AM
    Hi. I'm not able to instantiate the ViewModel. I'm getting the above error.
    d
    t
    • 3
    • 4
  • d

    dave

    12/16/2019, 1:18 PM
    Hi guys, how can I disable animations when running espresso tests? Have done everything I found on SO, everywhere. Yet animations done by : view.animate()... keep disabling my tests to continue running. Please some light here. Tried DisableAnimation rules, also gradle configurations, nothing works, few animations are disabled, OS level like transitions, but view animations are not. Kind regards.
    w
    • 2
    • 4
  • a

    Andy Gibel

    12/16/2019, 4:59 PM
    something that has confused me with coroutines is that you often see things done with runBlocking. Doesn't that sort of defeat the purpose of making a thing a suspend function?
    b
    j
    • 3
    • 15
  • a

    alex.tavella

    12/17/2019, 12:54 AM
    Does anybody know why they are stopping new development on
    dagger-android
    . I personally don't like it, just want to know more about the problems community faced with it and possibly advocating against it on my company (we use it for every feature).
    r
    t
    • 3
    • 7
  • t

    Timo Obereder

    12/17/2019, 11:32 AM
    using dagger2 would it be wise to inject adapters (passing the viewmodelprovider) into a viewmodel and call it from there in the fragment/activity instead injecting it in the activity/fragment itself? (reason from someone else being some configuration change bug) ..not sure if this seems more plausible then normal injection in the activity/fragment?
    a
    • 2
    • 3
  • a

    Ashutosh Panda

    12/17/2019, 1:58 PM
    Hey is there any platform like this for android dev in kotlin
    ❓ 5
    c
    • 2
    • 1
  • d

    Diego Almeida de Oliveira

    12/17/2019, 3:16 PM
    Hey guys 👋. From what I know a ViewModel shouldn't know anything about Android, meaning that it should not receive references such as Intent, Bundle, Uri, etc. Having this in mind, let's say I receive a lot of information from an Intent and I have a complex logic related to all this data. I believe the right way to do it is by delegating this logic to the ViewModel, but since ViewModel shouldn't receive the Intent, what would be a good approach? I came up with these approaches: 1. Get all data in the View layer and pass to the ViewModel through a function. This might not be good because as far as I know passing too many parameters to a function is not good. 2. Create a data class that will have all the data. In this way we might end up having too many data classes. 3. Create an interface that hides any Android related code:
    interface IntentInterface {
        fun getStringExtra(name: String?): String
        fun getIntExtra(name: String?): Int
        ...
    }
    
    class CustomIntent : Intent, IntentInterface {
    
        constructor() : super()
        constructor(intent: Intent?) : super(intent)
        constructor(packageContext: Context?, cls: Class<*>?) : super(packageContext, cls)
        ...
    }
    
    class SampleActivity: AppCompatActivity() {
    	...
    	fun handleIntent() {
    		viewModel.processReceivedData(CustomIntent(intent))
    	}
    	...
    }
    
    class SampleViewModel: ViewModel() {
    	...
    	fun processReceivedData(data: IntentInterface) {
    		val sampleValue = data.getStringExtra("sample_key")
    		...
    	}
    	...
    }
    w
    i
    d
    • 4
    • 4
  • r

    rattleshirt

    12/18/2019, 11:05 AM
    If I try to use kotlin android extensions with v1.3.61 I run into a
    Failed resolution of: Lkotlin/internal/ir/Intrinsic;
    Anyone experienced this before?
    a
    • 2
    • 4
  • w

    Will Nixon

    12/18/2019, 10:45 PM
    Hi all, I need to access drawables via template literals inside a RecycleView.ViewHolder like:
    "@drawable/${formatString(entry)}"
    Any thoughts on the best way to do this?
    b
    p
    • 3
    • 34
  • s

    Serhii K.

    12/19/2019, 9:22 PM
    Hello guys. I need advice. I have a
    PagedListAdapter
    I populate it using
    LivePagedListBuilder
    . Each list item has
    Favorite button
    . How it would be better to handle
    Favorite button
    state? I need to know if an item is already added to favorites and when the button is pressed I need to update
    Favorites database
    to delete or add this item. (I'm using architecture components in my app). Thank you. My solution: Inside
    onBindViewHolder
    I call the callback to my activity and pass an item and its position. ViewModel checks if this item is favorited or not and returns a result back to the activity, the activity calls
    adapter.notifyItemChanged(position)
    . Same goes for
    Favorite button
    click listener. I need to pass an adapter position to ViewModel I don't like it. I think this solution is really bad but I can't come up with something better.
    b
    c
    z
    • 4
    • 44
  • d

    Daniele Segato

    12/20/2019, 9:47 AM
    JakeWarthon stated here https://youtrack.jetbrains.com/issue/KT-20358 that this bug has been solved in Android Gradle 3.3 Alpha 11 plugin but I can reproduce it in Android Gradle 4.0 Alpha 6 plugin.
    val map = mapOf<String, String>()
    map.getOrDefault("foo", "bar")
    This gives no warning from either the compiler or lint and crashes at runtime (on Lollipop) with
    Fatal Exception: java.lang.NoSuchMethodError
    Am I missing something?
    m
    • 2
    • 1
  • s

    Slackbot

    12/20/2019, 3:48 PM
    This message was deleted.
    l
    m
    • 3
    • 2
  • b

    Byron Woodfork

    12/20/2019, 3:54 PM
    Does anyone know if it's possible to target a specific android device? For example, if I wanted all Samsung devices to do one thing. And all other devices to do another? I believe the answer is no, but just wanted to make sure.
    g
    • 2
    • 2
  • a

    Ayden

    12/21/2019, 9:06 AM
    Is this a good approach of creating retrofit?
    private val retrofit = Retrofit.Builder()
    //    .baseUrl(Constant.URL + Constant.VERSION)
        .baseUrl("<http://192.168.1.128:5000/api/>")
        .addConverterFactory(GsonConverterFactory.create())
        .build()
    
    interface RegisterRepository {
        @FormUrlEncoded
        @POST("/api/register")
        suspend fun register(
            @Field("email") email: String,
            @Field("password") password: String
            )User
    }
    object RegisterApi {
        val retrofitService : RegisterRepository by lazy {
            retrofit.create(RegisterRepository::class.java)
        }
    }
    p
    z
    • 3
    • 2
  • s

    sreich

    12/23/2019, 4:45 PM
    What do you guys prefer for making rest calls on Android, say a crud application that has to hit a RUST API a lot
    a
    • 2
    • 3
  • t

    tseisel

    12/24/2019, 9:19 AM
    For the needs of my app, I need to share some data access logic between a
    Service
    and a
    Worker
    . For that matter I introduced a
    Repository
    . Because the service needs to know when data from the repository have changed, the repository exposes data as
    Flow<List<Foo>>
    (making it a reactive repository). Since database access can be expensive i'd like to introduce some memory cache so that either the
    Service
    or the
    Worker
    can query the current
    List<Foo>
    faster. Where would you put that cache ? 1. As a field in the repository itself. 2. As a field in a decorator that wraps the
    Repository
    . 3. In the
    Service
    , by consuming the flow with
    broadcastIn
    . 4. You wouldn't use a memory cache, as
    Room
    loads fast enough.
    4️⃣ 1
    👍 1
    s
    b
    r
    • 4
    • 3
  • s

    Stefan Kanev

    12/24/2019, 2:11 PM
    not necessarily kotlin specific, but let's give it a try: I'm using Jetpack navigation to navigate between two fragments. One is a list of things, the other one shows a specific thing. On the list I'm getting an
    Observable<[Thing]>
    , and I'd really like to pass a
    Observable<Thing>
    to the second fragment. However, I cannot figure out how. I have the list observable in the first fragment's view model and my intuition is that when making the transition, there should be a way to prepare the view model for the second fragment and then it can find it via
    ViewModelProvider
    . Can't figure out how to do it, though. Maybe there's a totally different way. Any clues?
    a
    z
    • 3
    • 33
  • d

    Dylan

    12/27/2019, 12:08 PM
    Hey there, I'm trying to find a way to run a function every second until I stop it. Using RxJava, I can use
    Flowable.interval()
    (see the docs below), but I would like to use Kotlin Coroutines for that. Do you have any idea on how to do that? http://reactivex.io/RxJava/javadoc/io/reactivex/Flowable.html#interval-long-java.util.concurrent.TimeUnit-
    j
    • 2
    • 2
  • g

    genovich

    12/27/2019, 5:04 PM
    message has been deleted
    a
    • 2
    • 2
  • m

    Mike Nakhimovich

    12/28/2019, 1:56 AM
    You can open apks in Android studio. There is an option to compare to previous apk as well, you should be able to see what the added methods are
    r
    w
    n
    • 4
    • 13
  • j

    Jérôme Gully

    12/28/2019, 11:33 AM
    Hi, I want to have my database and repository properties into my Application class. It's working but I wonder if this is okey and clean way of doing this ? Maybe i will use dagger in the future but not now.
    class MyApp : Application() {
        val database: AppDatabase by lazy { AppDatabase.getInstance(this) }
        val dataRepository: DataRepository by lazy { DataRepository(database.documentDao) }
    }
    👍 1
    b
    • 2
    • 6
Powered by Linen
Title
j

Jérôme Gully

12/28/2019, 11:33 AM
Hi, I want to have my database and repository properties into my Application class. It's working but I wonder if this is okey and clean way of doing this ? Maybe i will use dagger in the future but not now.
class MyApp : Application() {
    val database: AppDatabase by lazy { AppDatabase.getInstance(this) }
    val dataRepository: DataRepository by lazy { DataRepository(database.documentDao) }
}
👍 1
b

Brendan Weinstein

12/28/2019, 8:42 PM
I think this is a great way to expose singleton application scope without adding in a framework.
If the dependency is application scoped might be worth throwing it in MyApp companion object for ergonomics
j

Jérôme Gully

12/28/2019, 10:04 PM
Thanks for the advice 🙂, cleaner than before
But for the database I use
this
, how can I pass application instance (for context) in the companion object ?
b

Brendan Weinstein

12/28/2019, 10:10 PM
class App : Application {
  companion object {
    lateinit var appInstance: App

    val dateabase: AppDatabase by lazy { AppDatabase.getInstance(appInstance) }
  }

  onCreate {
    appInstance = this
  }
}
j

Jérôme Gully

12/28/2019, 10:11 PM
Thanks 🙂
👍 1
View count: 1