How to make an extension function for showing Toas...
# android
i
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
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
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)