I found some info about how to access the context from the subclass and also some info about
runOnUiThread(new Runnable() {
public void run() {
// Do something
}
});
But in my case it does not work. The application is still running, but the activity is maybe already destroyed. The first (main) activity is the parent activity of the one where my TimerTask is created. My code:
TimerTask tt = new TimerTask() {
@Override
public void run() {
// do something (cut)
// and at the end show info
getParent().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getParent(),
getResources().getString(R.string.st_toast_msg_stopped),
Toast.LENGTH_LONG).show();
}
});
}
};
curTimer.schedule(tt, millisecondsUntilStop);
There is no error/ exception at log. But the toasted message is not shown. 🙁
Now I have no Idea what I can else do/ try. I hope someone of you can help me.
P.S.: Maybe I use the wrong context? But I tried also some other context like the Context of the current activity, the ApplicationContext, … .
Well you are using the wrong context here that is
getParent(). Instead of usinggetParent()try to use thecurrent_Activity.thislike this,