TimerTask
runs in a separate thread. Toast.makeText()
must be executed from a thread that has established a Handler/Looper
. Basically this means you need to make the toast on a thread that has the standard Android message/event dispatcher running in it.
Easiest way to do this would be in your checkDate()
method:
runOnUiThread(new Runnable() {
public void run() {
Toast toast = Toast.makeText(this, "SIMPLE MESSAGE!", Toast.LENGTH_LONG);
toast.show();
}
});
EDIT: I'm an idiot, that's not right. You can't call runOnUiThread() from a Service context
You need to use a Handler for this. In your service:
private Handler handler;
in onCreate()
of your service:
handler = new Handler();
in checkDate()
method:
handler.post(new Runnable() {
public void run() {
Toast toast = Toast.makeText(myService.this, "SIMPLE MESSAGE!", Toast.LENGTH_LONG);
toast.show();
}
});