4

Friends, In my application Toast message is Displayed in Activity say UserActivity.class..

That activity includes a button, in which it will Redirect to next Activity in OnClick of button..

What i want is that my Toast Message should display in UserActivity until user taps Button, if user Taps the button my toast message has to be Disappear and Next activity will appear..

Is it possible to do like this, if so how its possible?

Thanks Venkatesh.

Venky
  • 11,049
  • 5
  • 49
  • 66

1 Answers1

4

This is quite simple. Just call the cancel method on your ToastMessage as soon as you don't want to show the ToastMessage anymore. Refer Toast cancel()

onkar
  • 4,427
  • 10
  • 52
  • 89
RoflcoptrException
  • 51,941
  • 35
  • 152
  • 200
  • How can i make my toast to appear until Activity changes,now it disappear in 2 seconds? – Venky Mar 15 '11 at 09:45
  • Seeing as Toast messages always take a duration as parameter which can't be more than like 1-2 seconds (I don't remember exactly), you would have to constantly recreate the toast, no? I would argue that this is not the right way to use a toast and the OP should display the message in another fashion. – Codemonkey Mar 15 '11 at 09:45
  • @Venkatesh. You can choose between a long or a short duration (http://developer.android.com/reference/android/widget/Toast.html#setDuration(int)) If you want to display the toast even longer you could as soon as the toast disappear show exactly the same again, but if this is necessary I would maybe argue that Toast isn't the right thing to use here. Then you should switch to a custom dialog or something similar. – RoflcoptrException Mar 15 '11 at 09:47