android - the method getApplicationContext() is undefined -


public void onproviderdisabled(string provider) {     toast.maketext(getapplicationcontext(), "gps disabled", toast.length_short);   } 

so have, , shows error , tells me method getapplicationcontext() undefined type mylocationlistener

what should avoid error

since aren't in activity need pass context class. wherever instantiate class pass activities context

myclass myclass = new myclass(this); 

then create constructor in class accepts context param , use that

public class myclass {     context c;     public myclass(context context) {          c = context;      } } 

then when need use it

public void onproviderdisabled(string provider) {     toast.maketext(c, "gps disabled", toast.length_short); } 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -