Android Toast message doesn't show
Asked Answered
A

4

6

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

Ammoniac answered 16/5, 2014 at 12:50 Comment(8)
I assume you see those 3 logs in your logcat? Try cleaning your project.Breadboard
I can't reproduce the issue. Are you sure you're not just missing it? Try changing Toast.LENGTH_SHORT to Toast.LENGTH_LONGStearn
@XaverKapeller, Thanks bro. I remember Eclipse had this problem that we needed to clear project, restart and rebuild again. For sake of experience I did it but still have nothing!!!! When I'm opening Toast class there are some red lines that I don't know is because of them. let me update my question with image.Ammoniac
Those errors don't matter. They are normal since those two classes most likely have package visibility. You don't have to bother looking at framework classes...Breadboard
If you are trying on emulator, then try it on real device else no problem.Bibliolatry
Thanks Osama, I'm on real device. But good point let me test on other device.Ammoniac
@OsamaMohammedShaikh, Your suggestion was valuable to me. I tested on Android 4.3 It was working fine. My device is 4.1.2 but doesn't display. How come? I'm able to display toast message on my other apps? omg...Ammoniac
I don't know but sometimes old software becomes buggy.Bibliolatry
D
24

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

Dugas answered 17/5, 2014 at 10:6 Comment(3)
Exactly, have no idea when I did it. Anyways, thanks after 3-4 hours rotating around myself finally you told me the reason. Thanks...Ammoniac
Now I know why my users can't see any hint from my app. I thought that was my fault.Guide
I disabled notifications for all apps, but I uninstall the app and reinstall it and now it works... ?¿Disturbance
M
1

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.

Marismarisa answered 18/11, 2017 at 1:6 Comment(0)
S
1

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.

Significs answered 2/7, 2022 at 15:43 Comment(0)
P
0

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.

Pliny answered 16/5, 2014 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.