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
b

Bruno_

02/21/2020, 8:56 PM
I'm doing an interview homework that's an android app, the only thing that's left to do is network error handling I have no idea how to approach this, could you help?
i've tried implementing BroadcastReceiver but it wouldn't work
this piece of code is working but I'd have to setup a loop that would check the connection, I don't think that's the best idea
val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork: NetworkInfo? = cm.activeNetworkInfo
val isConnected: Boolean = activeNetwork?.isConnectedOrConnecting ?: false
b

Brian

02/21/2020, 9:01 PM
you can monitor for changes in connectivity using
ConnectivityManager.NetworkCallback
s

satyan

02/21/2020, 9:02 PM
Read ConnectivityManager documentation you should find something useful to handle the offline case. To handle network errors upon requests you should read your HTTP client documentation (Retrofit on top of OKHttp ? Java HTTP ? ) This Slack is supposed to be about Kotlin so it might not be the best place to ask interview homework questions. Try doing the Sunshine app application course on Udacity there must be a part about network calls.
b

Bruno_

02/21/2020, 9:05 PM
thanks, that'll solve the problem
or it won't, I have to support API14, would it be a good idea to listen for a flowable error somewhere?
not sure if it's a good idea tho, I've separated my retrofit module and I return flowable from it, the only place that has the flowable is a repository
this one works
r

Ryan Mentley

02/21/2020, 11:19 PM
as it happens I was semi-recently helping update one of the training articles on exactly this topic: https://developer.android.com/training/monitoring-device-state/connectivity-status-type
note specifically the bit about ConnectivityManagerCompat
a

Anastasia Finogenova

02/22/2020, 5:04 AM
You can always go for a retey button, on a snackbar or a dialog or even come up with a new UI for the network error state with the retry option , it is very straightforward imo
The network error will be returned differently depending on the network library you use. You mentioned you use Flowable so apparently RxJava, your network error is gonna fall in the the onError callback. So inside the onError callback check if the error is instance of Sockettimeoutexception or unknownhostexception if using retrofit and then just show your network error prompt with the retry
b

Bruno_

02/22/2020, 12:13 PM
the only place that has access to the flowable is the repository, which means that I can do
doOnError
only there. would it be a bad idea to throw an error in a repository and catch it in a fragment using a global exception handler? https://stackoverflow.com/questions/4427515/using-global-exception-handling-on-android
other solution would be to somehow use rxjava flowable instead of a view model (so fragment would call repository directly instead of fragment -> view model -> repository flow), is that a good idea?
I should probably mention that I use MVVM
@Anastasia Finogenova @Ryan Mentley
it's more of an architecture question, I know how to handle the rror, display a snackbar etc, I just don't know how to design the module properly
r

Raul Tunduc

02/22/2020, 12:25 PM
@Bruno_ you can check this too? https://developer.android.com/jetpack/docs/guide#addendum
❤️ 1
a

Anastasia Finogenova

02/22/2020, 8:57 PM
Just return this Flowable from the repo method and subscribe to it in the view model and do actions on result on success or on error
👍 1
Throwing an error in the repo and catching in the fragment is a very bad not straightforward idea
r

Raul Tunduc

02/23/2020, 8:28 AM
From my point of view, I would NOT recommend using RX for HTTP requests. It's easier with Coroutines
a

Anastasia Finogenova

02/23/2020, 7:33 PM
It is not easier imo, after using coroutines a lot I realized they are not easier in any way that RxJava from the dev stand point
I am recommending Flowable as he said he already has it
m

Mikael Alfredsson

02/24/2020, 9:28 AM
Since its an interview assignment, shouldn’t be able to solve it if youre qualified for the position? :troll: The error you should get back when you are trying to call the endpoint, so a normal try/catch works for that, and for the download automatically/retry, I would go for the first option and use Workmanager to achieve that.
b

Bruno_

02/24/2020, 2:31 PM
@Mikael Alfredsson it was my first real android app 😄 I'm a fullstack dev on a daily basis anyway, what I did was pretty much what you can see in the last SOF link I've sent - throwable field in a view model that I check on every view model update