Use application context to create toast (#7756)

(cherry picked from commit b0520df1dd4ff169f03b744954e181df94459efe)
This commit is contained in:
Ivan Iskandar 2022-08-14 19:44:24 +07:00 committed by Jobobby04
parent acfc76bdd0
commit aad81d9c79

View File

@ -69,7 +69,7 @@ fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT,
* @param duration the duration of the toast. Defaults to short.
*/
fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast {
return Toast.makeText(this, text.orEmpty(), duration).also {
return Toast.makeText(applicationContext, text.orEmpty(), duration).also {
block(it)
it.show()
}