Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 536
Hesam Avatar asked May 16 '14 12:05

Hesam


People also ask

Why is toast not showing messages?

The most important one , make sure your Android Notifications are on for your app, else the Toast will not be shown.

How do you show toast on Android messages?

Display the created Toast Message using the show() method of the Toast class. The code to show the Toast message: Toast. makeText(getApplicationContext(), "This a toast message", Toast.

Why is toast not working in Android Studio?

You're trying to display a Toast in a background thread. You should do all your UI operations on the main UI thread. The exception RuntimeException: Can't create handler inside thread that has not called Looper. prepare() can be a little cryptic for beginners but essentially it tells you that you're in a wrong thread.

How do I show message in center of toast?

A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.


2 Answers

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

like image 195
deekay Avatar answered Oct 08 '22 03:10

deekay


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.

like image 30
IrvineCAGuy Avatar answered Oct 08 '22 02:10

IrvineCAGuy