The program gives me an error in the context of the toast
. I already tried with getApplicationContext()
, with NombreActivity.this
and with only this
.
I have a main activity called ReaderActivity, from it I command to call ServiceListener, which is a java class.
Inside the ServiceListener is the toast inside an OnClick. Here I leave the code. [Here I command to call the Service Listener class
If your class extends from
Activity
,AppCompatActivity
etc, you can use:getApplicationContext()
,NombreActivity.this
orthis
If your class extends from
Service
you can use:But in this case you have to send the context to the class. In this case you can modify your class
ServiceListener
so that when you create it, you send the context from theActivity
, example:this way you can get the context in the listener class.
Now the variable
context
would be the one you would use as the context.