简体   繁体   中英

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.

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

你最后错过了show()方法。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM