Jürgen Steinblock Jürgen Steinblock - 4 months ago 13
Java Question

Cannot display Toast from an Activity other than my main activity

I have a Activity called main. If I call

Toast.makeText(this, "Hello World from main", Toast.LENGTH_SHORT);


this works fine. However, for every other activity in my application, I cannot display a Toast. No exception, nothing in the Log but I don't see the Toast.

My main activity starts another one with an options menu:

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {

case R.id.main_menu_entry:

Intent infolist = new Intent(this, infolist.class);
startActivityForResult(infolist, R.layout.infolist);

return true;
default:
return super.onOptionsItemSelected(item);
}
}


In my infolist activity I have another options menu which should display a Toast.

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.infolist_menu_entry:

// this Toast is never shown.
Toast.makeText(this, "Hello World from infolist", Toast.LENGTH_Short);
return true;

default:
return super.onOptionsItemSelected(item);
}
}


Any ideas what could cause this issue?
I am using the latest SDK with Min SDK Version = 3 and an 1.5 Emulator.

Answer

I would say, classical error :
You forgot the Toast.show() method ;)