Better Toast in Android

Posted by in Software

In my previous post, I’ve presented a Toast solution via a Handler and a Runnable. While that solution was a nice one and serves pretty well, I still got an exception. Therefore, I’ve decided to implement a builder-type wrapper to cover all situations:

  • Direct: just display a Toast,
  • Runnable: Build a custom Runnable to display a toast, apparently ideal for Services
  • AsyncTask: Use the onPostExecute() of an AsyncTask to display the Toast

The result can be used like:

The Full Code

At the time of writing, the code looks like this:

If it’s useful, I’ll publish it on Github.


A little experiment: If you find this post and ad below useful, please check the ad out šŸ™‚