I am trying to get the context of the app to print a Toast message. The function that I use in Java is the following:
Toast.makeText(getApplicationContext(), "Hey! I'm working", Toast.LENGTH_LONG).show();
But now, that I need to implement it in Kotlin, (language that I'm starting to learn) feel a bit lost. I have tried the following code (given in this post) but it doesn't work as I am not able to get the context of the app.
Toast.makeText(this@CoreMainActivity, "Its toast!", Toast.LENGTH_LONG).show()
Also, I am not able to get the context with getApplicationContext()
as described in the documentation.
I would be thankful to know how to call the getApplicationContext()
, and to understand what exactly this@CoreMainActivity
does (in the post this@CoreMainActivity
). Note that coreMainActivity
is a Java file.
Thanks!