I know this is a old question with many answers, like what I found here. But I still cannot see my toast message.
I tried check the current thread like:
Log.d("DEBUG", "Main Looper: " + Looper.getMainLooper().toString() + ", Current Looper: " + Looper.myLooper().toString());
Log.d("DEBUG", "Main Thread: " + Looper.getMainLooper().getThread().toString() + ", Current Thread: " + Thread.currentThread().toString());
//and the log is like:
D/DEBUG﹕ Main Looper: Looper{420a9e68}, Current Looper: Looper{420a9e68}
D/DEBUG﹕ Main Thread: Thread[main,5,main], Current Thread: Thread[main,5,main]
so I think I'm in the main thread(ui thread), and I also tried toast in ui thread specifically:
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getBaseContext(), "abc", Toast.LENGTH_LONG).show();
Log.d("DEBUG", "ui thread abc");
}
});
I can see the log "ui thread abc" but the toast still didn't appeared.
Then I think maybe the toast is overlapped by other views so I tried to specify the location of toast like: Toast toast Toast.makeText(getBaseContext(), "abc", Toast.LENGTH_LONG);
Toast toast = Toast.makeText(this, "abc", Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP|Gravity.CENTER, 0, 0);
toast.show();
Still get nothing. So what do you think is happening to my toast?
-------UPDATE
I'm in a activity with a vertical LinearLayout and several embedded horizontal LinearLayouts. I got only two activities now and I'm toasting in the main acvitity.
I'm using a custom image slider and toasting in the onclick event, the onClickMethod is like below:
public void onSliderClick(BaseSliderView slider) {
// Log.d("DEBUG", "Main Looper: " + Looper.getMainLooper().toString() + ", Current Looper: " + Looper.myLooper().toString());
// Log.d("DEBUG", "Main Thread: " + Looper.getMainLooper().getThread().toString() + ", Current Thread: " + Thread.currentThread().toString());
// Toast.makeText(getBaseContext(), slider.getBundle().get("testMsg").toString(), Toast.LENGTH_LONG).show();
// Toast.makeText(getApplicationContext(), slider.getBundle().get("testMsg").toString(), Toast.LENGTH_LONG).show();
// Log.d("DEBUG", "Slider - " + slider.getBundle().get("testMsg").toString());
Toast.makeText(getApplicationContext(), "abc", Toast.LENGTH_LONG).show();
Log.d("DEBUG", "msg abc 123");
// Toast toast = Toast.makeText(this, "abc", Toast.LENGTH_SHORT);
// toast.setGravity(Gravity.TOP|Gravity.CENTER, 0, 0);
// toast.show();
}
-------UPDATE 2
I just found that the action bar toast is not showing too, I did set the title element, I'm using a split action bar which is placed at the bottom of the screen.
Actually I can see all the toast messages before, then I made some change to the UI or some other stuffs, then all the toast disappeared. The problem is that I can't rollback to the older version which the toast is working good and I can't find the reason why they are gone now.
By the way after I added the custom image slider the toast is still good, and there isn't any other threads except the background thread which is auto switching the image slider.