Skip to content Skip to sidebar Skip to footer

Android Locationmanager Null Pointer Exception? (how To Pass The Context?)

I have a problem here and I cant get it to work... I want to get the latest gps positions but all i get is an null pointer exception. It works with the first class GPSActivity but

Solution 1:

declare a new locationManager in the smsReceiver class and use the following lines

mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
 Locationloc= mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

Solution 2:

Create the One class which extends the Service and into this implement the GPS task because in Activity which will stop/pause/destroy and you can't get every time. Service will run into background so you can get the GPS co-ordinate at any time any and define the location object as public static so you can use anywhere into your application.

Post a Comment for "Android Locationmanager Null Pointer Exception? (how To Pass The Context?)"