https://kotlinlang.org logo
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
benchmarks
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
confetti
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
lincheck
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
Title
u

ursus

10/23/2018, 11:26 PM
lmao that comment about rx, whats next, dont write unit tests because only bad devs make bugs? 😄 rx is amazing, general android app code is much better because of it, and actually handles much more, where before race conditions would be yolo and only fixed when bugs reported etc. or doing stuff from callback of something else, that needs certain conditions to happen. before this would be if !conditionsOk return, and yolo most of the time
l

louiscad

10/24/2018, 5:53 AM
In many cases, you can do easier (to write and read), an safer with Kotlin #coroutines. Rx, especially RxJava(1&2) is extremely complicated, and non natural when what you want to do is just doing some processing off the main thread, or wrap a few callbacks.
u

ursus

10/24/2018, 6:41 AM
sure..rxjava predates cooroutines, and is superset of cooroutines, so, same thing different api
r

radityagumay

10/24/2018, 2:12 PM
It depends how deep you know RxJava is.
u

ursus

10/24/2018, 2:47 PM
sure, im. not arguing against cooroutines
r

rkeazor

10/24/2018, 3:48 PM
@louiscad, RX java isn’t complicated. I think everything is hard until you learn it. Also the use case for RX Java vs Coroutines, is completely different. A better argument would be, Coroutines vs Threads…
RX Java and Coroutines are not the same The only similarity they have is that you can specify the thread operations run on … Coroutines is dealing purely with concurrency.. RX java is dealing with event driven observable sequencing. You can argue that you can achieve some of the same sequencing with kotlin functions. But to say they are the same API or one could replace would be incorrect, would be incorrect. Its like me trying to say, RX Java could replace threads lol
u

ursus

10/24/2018, 5:14 PM
oh trust me rx can be complicated 😄 but yea I see what you are saying that most people are using it just as asynctask, such a waste. .. never said rx and cooroutines were the same
what I meant is that rx made handlign difficult scenarios easy, so ..they get handled, same as when you have faster computer, you do more computing
but if it is complicated for noobs, cooroutines will do as well, better than yoloing raceconditions etc.
l

louiscad

10/24/2018, 11:00 PM
@rkeazor Coroutines are about removing callbacks hell, which includes thread switching and concurrency. They allow sequential, yet asynchronous code. A lot of people use RxJava for these very same reasons only, but this ends up in many inefficiencies compared to what they could do with just coroutines (memory-wise, but also regarding effort needed to read and write such code).
r

rkeazor

10/24/2018, 11:13 PM
@louiscad Ahh, no Corutines are not about removing callbacks lol. Like you wouldn't replace a onClickListener with a coroutine lol. And Rx uses call backs under the hood. . Corutines is all about concurrency.Suspending functions, deferred function, async await, that's all concurrency. They are not the same thing. You do know there is a coroutines extension for Rxjava. They are different. They solve different problems. There is no comparison to be honest. The debate your looking for is between Coroutines and Threads...
Rxjava, is the best for what It does. Why do you think its recognized by so many dev's.
u

ursus

10/25/2018, 3:25 AM
I dont see how cooroutines is better perf / memory wise, isnt that just an abstraction thats sitting on top of java threads, sort of like rx schedulers are
r

radityagumay

10/25/2018, 3:36 AM
Man both RxJava and Couroutine has their respectively advantage. For example A is Rx and B is Couroutine. But both of them can works for same cases. There are cases that we should use Rx and there are cases we should using Couroutine. Under the hood Rx is promoting Observable Stream Chaining, and Couroutine is promoting light weight thread. For example the similarly both Rx and Couroutine are. Rx Publish Subject is equal to Couroutine Channel. Rx Behavior Subject is equal to Couroutine ConflatedChannel. I can give you more examples. But, you should working by using both of them to know how both works.
r

rkeazor

10/25/2018, 3:55 AM
Right, Both are good for what they do. Rx java is great for manipulating streams of data . Coroutines is way better than Threads and executors
👌 1
🙂 1
r

radityagumay

10/25/2018, 3:58 AM
Correct
u

ursus

10/25/2018, 4:23 AM
I dont even know what we are talking about, im avid rx user and wont switch to cooroutines lol, I just reacted to that google nonsense, and how rx improved my code
cant someone just tell me how to restore observable chains supscriptions etc so I dont need to retain viewmodel / presenter? 😄
r

radityagumay

10/25/2018, 4:55 AM
Use connectable observable @ursus
I believe you know about replay(), autoConnect(), publish(), refCount(), share(), and how to use cross those factories.
Even you no need view model to retain. Under the hood view model is just a fragment with retainInstance = true, and additional sugar. Old Android API which is Loaders also will survive when device orientation changed.
@ursus I am also avid rx users, btw. But, I do keep learning something new and trying to compare with existing stack. If new stack is make sense to replace existing, I will use that. If no, absolutely will not replace.
l

louiscad

10/25/2018, 6:14 AM
@rkeazor Actually, I have a function like this:
suspend fun View.awaitOneClick(…)
which has use cases in my codebases, and it sets an on click listener 😉
r

radityagumay

10/25/2018, 6:15 AM
awesome. @louiscad
u

ursus

10/25/2018, 6:48 AM
@radityagumay well that requires the obs. instance to be placed in some layer above viewmodel. I dont like retaining because then I cannot have any view references or transitive a activity references, which fails horribly when you need like permssions, picture in picture etc.
r

radityagumay

10/25/2018, 6:49 AM
@ursus yes, you're right
u

ursus

10/25/2018, 6:50 AM
well, having a static layer just to perform rotations, idk how I feel about that
r

radityagumay

10/25/2018, 6:51 AM
you can use headless fragment tho.
u

ursus

10/25/2018, 6:51 AM
well, I do, but then if I need to do something in activity, i need to emit Command objects
like Command.GoToFooActivity
bit if you need something like activity.enterPipMode which returns boolean, you are screwed
r

radityagumay

10/25/2018, 6:52 AM
i never had implements of view bind in Activity. Activity only for container for attaching fragment or view
u

ursus

10/25/2018, 6:53 AM
Doesnt matter, pick anthing you need activity for
or a view, like webview..
r

radityagumay

10/25/2018, 6:55 AM
to be honest never use PIP mode. but, i already use Single Activity Architecture. only navigate to the screen, by using Navigator,goTo(screen)
u

ursus

10/25/2018, 6:57 AM
well yes single activity saves you
what about views, id like to pass textViewObservsblr as to viewmodel ctor
or something async like textureView where you need to listen to onAvailable callback
r

radityagumay

10/25/2018, 6:59 AM
just like you using RxBinding
u

ursus

10/25/2018, 6:59 AM
well you cant since it will leak if you retain viewmodel
you need to do a silly dance if relays
or do it in view
r

radityagumay

10/25/2018, 6:59 AM
then disposed it
in appropriate callback
u

ursus

10/25/2018, 7:01 AM
nah, the observable itself will have reference to view
if you pass to val of viewmodel
r

radityagumay

10/25/2018, 7:02 AM
interface SignInView {
  // Produces.
  Observable<String> login();
  Observable<String> password();
  Observable<Object> signInClicks();
  
  // Consumes.
  Function<Observable<Boolean>,      Disposable> signInEnable();
  Function<Observable<SignInResult>, Disposable> signInResult();
}
i used to did like this
u

ursus

10/25/2018, 2:17 PM
are you sure if you pass Observable<String> login(): to retained view model, you are not creating a leak?
r

rkeazor

10/25/2018, 2:36 PM
@ursus as long as you assign it to a subscriber and unsubscribe it on onClear, you can’t create a memory leak.and don’t get me wrong Im not arguing against coroutines, I am saying people are creating the wrong argument. Coroutines is all about concurrency, so you should compare it to other concurrency models,like Threads.. Like you wouldn’t compare Threads to RX java because that wouldn’t make sense lol….
u

ursus

10/25/2018, 2:40 PM
I need to think about this harder but I dont think you are right. If you unsubscribe onClear, from a observable that comes from UI (not other way around), view.onDestory will come sooner than viewmodel.onClear (after rotation there is no onClear and is onDestroy)
hence you creating a leak
youd need to attach to VM in on View.onCreate(or vm ctor whatever) and detach it from VM in View.onDestroy, only this I THINK wont create a leak
r

rkeazor

10/25/2018, 2:51 PM
If its coming from the UI. You use AndroidSchdulers.mainThread
but if your using Lifecycle component , you can handle all of in the viewmodel
You just need to unsubscribe at the right place… If you don’t assign the observable to a subscriber, you will get a leaked subscriptions warning
if RX is use properly there won’t be memory leaks. Its not like the API has a memory leak feature lol
u

ursus

10/25/2018, 3:29 PM
you are talking about something else. I am talking about observable view -> viewmodel. NOT viewmodel -> view
r

rkeazor

10/25/2018, 6:11 PM
Than you have AndroidSchdulers.
I don’t see the problem.
or just unsubscribe in onPause and onStop
Theoretically speaking, your view shouldn’t be inside your ViewModel. So if your using RXandroid you just need to set it to a subscription and unsubscribe when needed
u

ursus

10/25/2018, 9:23 PM
I dont know what you mean. There is no onPause in viewmodel? The leak is if you have a view reference (whitch has a activity reference) in a retained viewmodel after rotation, because its a hard reference in a viewmodel, so you keep it from GCing
r

rkeazor

10/26/2018, 2:05 AM
Why would you have a view reference in the viewmodel?
a view belongs in the View of MVVM, not in the VM
Thats not a issue with RX , thats a issue with the architecture lol…
The main idea ,is that RXJava doesn’t cause memory leaks. There is no underling issue with the API. Bad Code causes memory leaks '
Like I can sit here and think of a thousand and one ways to create a memory leak with Coroutines. It doesn’t mean Coroutines causes memory leaks, it just mean my code did
u

ursus

10/26/2018, 5:29 AM
What? I never said rx api causes leaks. Well you could argue rx view binding would be nice in viewmodel. But the main use case is somethimg that requires activity context, but is not a view.. like pip, permissions etc.
which you cannot have the reference to in a retained viewmodel so please dont repeat that onPause disposal thing
r

rkeazor

10/26/2018, 12:43 PM
@ursus and what I am saying is that your wrong. For one , in the documentation it literally tells you not to directly reference views and context in your viewmodels because it causes memory leaks. Like that literally the disclaimer for using viewmodels. And if you do need context it tells you, to use AndroidViewModel which provides the application viewmodel... Like this is literally in the documentation... So creating this hypothetical about a memory leak, is not a limitation of Rx Java, it's literally just bad coding, and someone not reading the documentation...
And what I'm saying about onPause is that, if you use RxAndroid in your *activity *(not viewmodel) that you should assign it to a subscriber and unsubscribe when needed. Like during onPause... which is correct. Like if you don't do that you literally get a Leaked Subscriptions warning lol. I don't know why we are even debating about this
u

ursus

10/26/2018, 2:45 PM
Okay I give up. I am debating code design in general to improve how we do things on android, and you are saying I cant because google library docs say I cant, lol
r

rkeazor

10/26/2018, 4:14 PM
From all perspectives you can’t. From a code design perspective, view related stuff don’t belong in the Viewmodel lol…
Android Jetpack is the improvement on how we do things. But ya still got to follow the rules 😂
u

ursus

10/26/2018, 4:20 PM
Okay clearly you dont get it, dont wanna waste your time anymore, thanks