Hi,
Imagine I have the following code that runs as a background processor for an android application:
public class Background extends Service
{
public void popup (String message, int duration)
{
Toast.makeText(this, message, duration).show();
}
class BackgroundChecker extends TimerTask
{
public void run()
{
popup("Message!", Toast.LENGTH_LONG); // here
}
}
}
When it reaches the popup message i.e. // here, Android tells me to force quit. I know that the problem is with context i.e. this
, but I don't know why because I have extended Service in that class which Android API told me to. Can you help me figure out why this is happening and how to fix it? By the way, instead of this
I used getApplicationContext()
as well but it still crashes =(.
Thank you.