Jürgen Steinblock
Jürgen Steinblock

Reputation: 31743

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.

Upvotes: 3

Views: 4683

Answers (2)

Gnanaprakasam
Gnanaprakasam

Reputation: 171

You miss the show() method at the end.

Toast.makeText(this, "Hello World from infolist", Toast.LENGTH_Short).show();

Upvotes: 0

Sephy
Sephy

Reputation: 50412

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

Upvotes: 10

Related Questions