开发者

How to display toast from one activity to another

开发者 https://www.devze.com 2023-02-14 15:06 出处:网络
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)

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...


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消