Android Toast message not showing

I know that there are some other problems associated with this problem, however mine is unexpectedly different (at least I think so).

I assume my code is right, but I have no idea why the toast message is not displayed. Firstly, I could not see the toasts in my fragments. Then I decided to include it in my activities and, oddly enough, it does not appear here either.

This is a code of my activity that 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();

.
.
.
} 

The application works fine without errors, and only this message f.toast is not displayed! I even replaced mContext with getApplicationContext (), and I had the same result, the toast is not displayed.

Any suggestion will be appreciated. Thanks

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

: Toast, . ,

enter image description here

+4
3

, ? .

+17

mContext "this", , ... , , , , MainActivity.

0

- ... , :

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

, setGravity. .

0

Source: https://habr.com/ru/post/1540836/


All Articles