AndroidMapper: return result in Bundle.

It's (may be) the last article in the series of AndroidMapper. Here, methods exitOk() and exitCancel() in AndroidMapView were implemented to return or ignore the updated location back to the main activity, AndroidMapper. As you know, a application return nothing after processed is useless!



In exitOk() method in AndroidMapView, the updated location will be packed inside Bundle, and finish() with RESULT_OK.
private void exitOk()
{
Bundle bundle = new Bundle();
bundle.putInt("Longitude", updatedGeoPoint.getLongitudeE6());
bundle.putInt("Latitude", updatedGeoPoint.getLatitudeE6());
Intent intent = new Intent();
intent.putExtras(bundle);
setResult(RESULT_OK, intent);
finish();
}


In exitCancel() method in AndroidMapView, simple finish() with RESULT_CANCELED.
 private void exitCancel()
{
Intent intent = new Intent();
setResult(RESULT_CANCELED, intent);
finish();
}


In onActivityResult() in AndroidMapper, resultCode will be checked if it's RESULT_OK. If yes, the data inside Bundle will be used to update mylongitude and mylatitude.
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(resultCode==RESULT_OK)
{
Bundle extras = data.getExtras();
String mylongitudeText = String.valueOf((float)extras.getInt("Longitude")/1000000);
String mylatitudeText = String.valueOf((float)extras.getInt("Latitude")/1000000);
mylongitude.setText(mylongitudeText);
mylatitude.setText(mylatitudeText);
validLocation();
}
}


Download the files.