I am trying to get a user's location when a button is clicked.
I have the following code in my button onclick listener:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
bestProvider = locationManager.getBestProvider(criteria, false);
Location currentLocation = locationManager.getLastKnownLocation(bestProvider);
Log.e(tag,"reached till here");
location = Double.toString(currentLocation.getLatitude()) + " " + Double.toString(currentLocation.getLongitude());
Toast.makeText(getApplicationContext(), location, Toast.LENGTH_LONG);
MyLocation.setText(location);
I am getting the the output reached till here
in logcat. After that the application stops and asks me to force close it. I initially did some searching and found out that getLatitude and getLongitude return double values. So I corrected the code. But still I am getting an error. What am I doing wrong?
EDIT : The logcat error:
Got RemoteException sending setActive(false) notification to pid 796 uid 10036
I think currentLocation is returning null