Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Toast Won't Disappear

Tags:

android

I show the toast, it doesn't disappear, even after the app is closed. How do I fix?

@Override
public void onClipStoreLoadedClipsNotification(ClipStoreLoadedClipsNotification notif) 
{
    final ClipStoreLoadedClipsNotification notification = notif;

    runOnUiThread(new Runnable() {
        @Override
        public void run() 
        {
            Dialogs.DismissAll();
            list.onRefreshComplete();
            TextView text = (TextView)findViewById(R.id.loadclipstext);
            ProgressBar pb = (ProgressBar)findViewById(R.id.loadclipsprogress);

            if (notification.moreClipsAvailable)
            {
                text.setText(context.getString(R.string.loading_clips));
                pb.setVisibility(View.VISIBLE);
            }
            else
            {
                text.setText(context.getString(R.string.no_clips));
                pb.setVisibility(View.INVISIBLE);
                int duration = Toast.LENGTH_SHORT;
                Toast.makeText(SugarLoafContext.playbackTabContext, "No clips found.", duration).show();
            }

            SugarLoafContext.currentCamera = notification.camera;
            clipList = notification.clips;

            refreshListView();
            readyToLoadMoreClips = true;
            if (!firstClipsLoaded)
                firstClipsLoaded = true;
        }
    });


}
like image 766
spentak Avatar asked Sep 06 '11 14:09

spentak


People also ask

How do I get rid of toast message?

If you call toast. dismiss without argument, all the displayed toasts will be removed.

Why is my toast not showing Android?

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

What are Android toasts?

A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive. Toasts automatically disappear after a timeout.


1 Answers

Is it running inside a IntentService???

If it is so, the problem is that the Intent Services in Android run in a different thread than the main one, so the Toast is shown in a different thread than the main one, after the time to show is finished, the Android system is unable to find where is the Toast, so it can´t remove it.

I had the same problem, and now, i recommend everyone NOT to show Toast inside a IntentService, instead try to run one commom Service, or to open an Activity, or try something different if it is completely necessary to show the Toast.

The fact that the Toast doesn´t dissapear when you close the App is that the IntentService is still running, and you have to reboot the system or to uninstall the App for the Intent Service to be close.

like image 125
zapotec Avatar answered Oct 06 '22 10:10

zapotec