如何从一个LocationListener的的onProviderDisabled方法内部发出通知 [英] How can I send a notification from inside the onProviderDisabled method of a LocationListener

查看:780
本文介绍了如何从一个LocationListener的的onProviderDisabled方法内部发出通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从一个LocationListener的的onProviderDisabled方法内部发出通知?

How can I send a notification from inside the onProviderDisabled method of a LocationListener?

到目前为止,我一直在使用:

So far I have been using:

Toast.makeText(mainmenu, "GPS Location providers are disabled... blah blah", Toast.LENGTH_LONG).show();}});

但这就需要使用时的MainMenu类第一次实例存储静态MainMenu的变量 - 我猜想这样做这是一个坏主意,万一MainMenu的对象被从内存中删除我想 - 所以我想我应该使用通知

but that entails using a static mainmenu variable stored when the mainmenu class is first instantiated - I gather doing it that is a bad idea, in case the mainmenu object gets removed from memory I guess - so I think I should be using notifications.

我想我需要能够有一个活动的引用,使意图 - 但我可以参考什么活动,因为我的位置监听器店没有这样的参考

I guess I need to be able to have a reference to an activity to make the intent - but what activity can I refer to since my location listener stores no such reference?

推荐答案

我不知道这是否会一直工作,但你可以叫 Application.getApplicationContext()并使用它。

I'm not sure if this will work always, but you can call Application.getApplicationContext() and use that.

如果您LocationListener的是一种活动的一部分(在一个内部类的形式),你也可以使用 this.MyActivity

If your LocationListener is part of an Activity (in the form of an inner class) you can also use this.MyActivity.

这篇关于如何从一个LocationListener的的onProviderDisabled方法内部发出通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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