I have an activity called message.java which is bound to the service GPS.java. The latitude and longitude obtained from GPS.java has to be used in message.java. We are getting the default values of latitude and longitude in the onServiceConnected() by using servicebinder.
Here is the code for message.java
`Intent i=new Intent(getApplicationContext(), GPS.class);
bindService(i,mConnection,Context.BIND_AUTO_CREATE)
private GPS servicebinder;
ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
servicebinder = ((GPS.MyBinder)service).getService();
double lat=servicebinder.getlatitude();
double lon=servicebinder.getlongitude();
tex.setText("\nlatitude: " + lat+ "\nlongitude: "
+ lon);
// do any extra setup that requires your Service
}
getLatitude() and getLongitude() return the latitude and longitude found in GPS.java which is correct. The problem is the lat and lon shown above prints the default values, so when the latitude and longitude in the service is updated i want the lat and lon also should be updated (Activity should be notified on service updation)
Please give the code to place them appropriately
First Create the Interface like
MyLocationListeneras followingNow Update the
GPSclass asSo Where you have changed the latitude or longitude just call the
and this method has following code:
This is the first part, now the second thing is to add the listener in your activity, by Making an class
MyServiceConnectionwhich is like:Now just register the listener
gps.addLocationListener(mConnection);