开发者

Android Toast Won't Disappear

开发者 https://www.devze.com 2023-04-02 15:02 出处:网络
I show the toast, it doesn\'t disappear, even after the app is closed. How do I fix? @Override public void onClipStoreLoadedClipsNotification(ClipStoreLoadedClipsNotification notif)

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))开发者_StackOverflow;
                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;
        }
    });


}


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.


The only explanation is that your Toast is called in a loop. You should track the toast .show() and see if it is not called an infinite times.

An other visual way would be to do this

 Toast.makeText(SugarLoafContext.playbackTabContext, "No clips found.", duration).show();
 Toast.makeText(SugarLoafContext.playbackTabContext, "Do you understand now?", duration).show();

I am sure you will see both toast alternatively during a looong time...


This can also happen if your device has no network connection, and your app does a license check and shows a Toast of results. One of my apps had this problem, as I was displaying a Toast when checking the app was licensed. Without a network connection the Toast telling the user that a license retry was to be done remained, and when I connected the Toast was removed, because the license check could work.

0

精彩评论

暂无评论...
验证码 换一张
取 消