How to show Toast on homescreen

240 Views Asked by At

I have an activity that uses:

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()

To automatically return to the home screen once the function above is called, but the toast does not show up. How can I make a toast show up while on the home screen?

1

There are 1 best solutions below

0
Narendra_Nath On BEST ANSWER

The this stands for the context. So instead of using this use applicationContext

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