Hesam
Hesam

Reputation: 53610

Android Toast message doesn't show

I know there are some other issues regard this problem, however, mine is surprisingly different (at least I think so).

I guess my code is right but I don't have idea why toast message doesn't display. Firstly, I couldn't see toast message in my Fragments. Then I decided to put it in my activity and amazingly it doesn't display here too.

This is code of my Activity which has been extended from FragmentActivity.

@Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        Log.d(TAG, "***************************");
        Log.d(TAG, "*** Application started ***");
        Log.d(TAG, "***************************");

        // assign layout to activity
        setContentView(R.layout.activity_main);

        mContext = MainActivity.this;
        Toast.makeText(mContext, "Hello World", Toast.LENGTH_SHORT).show();

.
.
.
} 

Application works fine without error and just this f.toast message doesn't display! I even replaced mContext with getApplicationContext() and I had same result, toast does not display.

Any suggestion would be appreciated. Thanks

===============

Update: When I open Toast class there are some red lines. please look at image below

enter image description here

Upvotes: 6

Views: 9611

Answers (4)

Taha Körkem
Taha Körkem

Reputation: 906

I also faced this problem. My problem was that a particular emulator was not showing any toast message although other emulators and real devices were. I could solve the problem after closing the emulator and removing folder <YourUserName>\.android\avd\<EmulatorName>.avd\snapshots.

Upvotes: 1

IrvineCAGuy
IrvineCAGuy

Reputation: 211

something may be hiding your toast...so I use this when that appears to be the case:

    Toast toast = Toast.makeText(TaskEdit.this, "Task Saved", Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER_HORIZONTAL,0,0);
    toast.show();

You can change the position of the toast location using the various setGravity options available. Happy Coding.

Upvotes: 1

deekay
deekay

Reputation: 681

Perhaps you have accidentially disabled notifications for your app in the settings? This causes no toasts too.

Upvotes: 24

Imheroldman
Imheroldman

Reputation: 21

Try replacing mContext with "this," at least that is how i have been using it... Rather than typing the extra lines of code you can simplify, seeing you are within the MainActivity already.

Upvotes: 0

Related Questions