Domen Tomažin
Domen Tomažin

Reputation: 95

How to display toast from one activity to another

I have a question. Is it possible to display a toast message (in if condition) from HttpDownload class to AnimalBadger class? (Both classes extend Activity)

if (((Node) textNodes.item(i)).getNodeValue().equals("a waning quarter moon")) 
{
    Toast.makeText(HttpDownload.this, "Some text...", Toast.LENGTH_LONG).show();
} 

Thanks for the answers...

Upvotes: 2

Views: 4139

Answers (2)

James Andino
James Andino

Reputation: 25789

You could use a call back function and register it with HttpDownload class. That way the call back is called which will throw the toast(pun intended).

Upvotes: 0

jakebasile
jakebasile

Reputation: 8132

The first argument is just to get the Context to create the Toast with. You can use either activity or even getApplicationContext(). For simplicity, you usually use the closest available Context, which in this case would be your containing activity.

Toasts are not sent between application components, they take the form of small notifications usually at the bottom of the screen, and are a way to communicate low-priority messages to the user.

You may want to read the Creating Toast Notifications article in the documentation.

Upvotes: 2

Related Questions