如何在主屏幕上显示Toast



我有一个活动使用:

val i = Intent(Intent.ACTION_MAIN)
i.addCategory(Intent.CATEGORY_HOME)
startActivity(i)
Toast.makeText(this, "Fetching attendance, hold your phone close to the terminal ...", 
Toast.LENGTH_SHORT).show()

当上面的函数被调用,但是toast没有出现时,自动返回主屏幕。如何在主屏幕上显示祝酒词?

this代表上下文。所以用applicationContext

代替this
Toast.makeText(applicationContext, "Fetching attendance, hold your phone close to the terminal ...", 
Toast.LENGTH_SHORT).show()

最新更新