Question: I am using toast on android, However I dont want the toast to disappear. but rather stay...
And I dont want the toast to show up on different activity or fragment.
If I called toast in certain fragment, i dont want it to be seen in a different fragment or activity.
Lets say activity 1, i call toast..i go to activity 2... i dont want toast to be displayed yet. when i return to activity 1 i see the toast still in place.
I also want this for fragments.

> 
> Toast toast = Toast.makeText(dialog.getContext(),R.string.serverError, Toast.LENGTH\_LONG);
>  toast.show();
> 
> 
>

Answer: 
One possibility is to make the Toast `global` in your Fragment/Activity. Now you can call [Toast.cancel()](http://developer.android.com/reference/android/widget/Toast.html#cancel%28%29) in a callback like `onPause()`, which is called if you switch an Activity or Fragment. 

The docs say about cancel:

> 
> Close the view if it's showing, or don't show it if it isn't showing
>  yet. ...
> 
> 
> 

A nicer way is to make a custom class for the Toast like jitain sharma suggested in the comments.
Use below code in your activity `onDestory` method:

```
toast.cancel();

```