In different Kotlin examples for Android I see toast("Some message...")
or toastLong("Some long message")
. For example:
With this extension function for Toasts, you can call them in Activities as well as Fragments, you can pass this as Context
for Activities or getApplication()
for Fragments, also it's generated with Toast.LENGTH_SHORT
as default, so you don't need to worry to pass it as a parameter, but you can overwrite it as well if you need.
fun Context.toast(context: Context = applicationContext, message: String, duration: Int = Toast.LENGTH_SHORT){
Toast.makeText(context, message , duration).show()
}
toast(this, "John Doe")
if you want to overwrite the duration.
toast(this, "John Doe", Toast.LENGTH_LONG)