我如何从非活性类举杯? [英] How do I make a toast from a non activity class?

查看:111
本文介绍了我如何从非活性类举杯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用得到在我的活动GPS数据的类。在构造函数中我将它传递活动的背景下:

I have a class that I am using to get GPS data within my activity. In the constructor I pass it the activity's context:

gpsFetcher = new GPSFetcher(this);

和在gpsFetcher I类有:

and in the gpsFetcher class I have:

this.context = c.getApplicationContext();

或只是

this.context = c;

然后我打电话吐司:

and then I call the toast with:

Toast.makeText(context, "sometext", Toast.LENGTH_LONG);

但它一直没有出现......有我丢失的东西?这可能吗?

But it never shows up... Is there something I'm missing? Is it possible?

谢谢!

推荐答案

你是不是忘记吐司#秀

Toast toast = Toast.makeText(context, "sometext", Toast.LENGTH_LONG);
toast.show();

这篇关于我如何从非活性类举杯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆