I am still new to Android development, and I still don’t know a decent way to write code. Currently I throw everything into my MainActivity. But I don’t think that is a good way to write it. I have been searching Google, but I don’t really know what to search for. Does anyone have any tips?
I was going to try and take some code that I have and throw it into a view, but when I do I get errors.
For example when I place this in a view, I get cannot find symbol LOCATION_SERVICE
public class MainView extends View{
public double[] getLoc(){
// Get the location manager
LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
}
}
That is basically a snippet from a function that gets a users latitude and longitude. It doesn’t work in a view I assume. The code does work in my MainActivity though.
use
instead of
for accessing
LOCATION_SERVICEand you also need to use current context for calling getSystemService method to get Service as :