How To Return Data In Android Locationlistener
i want to build an app in which users can make foto which is tagged with the current location of the phone. So after making a foto, the user can save the picture by touching on the
Solution 1:
Why not pass your own callback from activity to MyLocationListener and call its method from finishTracking?
Its a commonly used delegation pattern. Something like that:
classMyLocationListenerimplementsLocationListener {
publicinterfaceMyListener {
voidonLocationReceiver( Location location );
}
private MyListener listener;
publicMyLocationListener(Context context, ProgressDialog dialog, MyListener listener) {
mContext = context;
progressDialog = dialog;
this.listener = listener;
}
privatevoidfinishTracking(Location location) {
if(location != null) {
locationManager.removeUpdates(this);
progressDialog.hide();
Log.i("TRACKING",location.toString());
listener.onLocationReceiver(location);
}
}
}
and call:
new MyLocationListener(this, dialog, new MyLocationListener.MyListener() {
public void onLocationReceived( Location location ) {
text.setText(location.toString());
}
}).startTracking();
Post a Comment for "How To Return Data In Android Locationlistener"