https://kotlinlang.org logo
#android
Title
# android
i

Ive Vasiljevic

05/09/2019, 3:03 PM
How to make an extension function for showing Toast inside of both Activity and fragment. My take on this:
Or should I make an extension function for Activity and Fragment to cover both cases?
t

tseisel

05/09/2019, 3:27 PM
I find it safer to define a separate extension for
Activity
and
Fragment
, as
Context
can also refer to the application context. Not sure that using the application context would prevent from showing the toast, but UI things should be called from UI code.
👍 1
s

Sam

05/09/2019, 4:00 PM
If possible, try to get away from Toast. android core ktx used to have this extension and it got removed a while back
Use other widgets like snackbar (with undo etc)
14 Views