How to display a Toast message in from a class that doesn't extend Activity

user1513889 picture user1513889 · Jul 13, 2012 · Viewed 33.7k times · Source

Possible Duplicate:
How do I make a toast from a non activity class?

How can I create and show a Toast message from a class which does not extended the Activity class? I'm using this class in another class that is extended by Activity.

Answer

Blackbelt picture Blackbelt · Jul 13, 2012

You need a context Reference. Just have a helper method like

  public static void showToastMethod(Context context) {
        Toast.makeText(context, "mymessage ", Toast.LENGTH_SHORT).show();
  }