I have a class
that extends AppCompatActivity
. Within this activity I do two different calls to two startActivityForResult
methods which are hooked to two button listeners. The first one calls a camera intent like so:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
and the second one calls another AppCompatActivity
which holds a Google Map to wit:
Intent getLatLongIntent = new Intent(Form.this, MapsLatLongActivity.class);
startActivityForResult(getLatLongIntent, LATLONG_REQUEST);
The first startActivityForResult
works fine and I can manipulate the response from the camera intent in the onActivityResult
method. What is puzzling is that the same onActivityResult
does not get triggered when I close the child activity of the second call using this code:
Intent intent = new Intent();
intent.putExtra("brdgHouseLat", latitude);
intent.putExtra("brdgHouseLong", longitude);
setResult(RESULT_OK, intent);
finish();
Below is my code for the onActivityResult
method:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
himgres.setImageBitmap(photo);
} else if (requestCode == LATLONG_REQUEST && resultCode == Activity.RESULT_OK) {
latitude = data.getDoubleExtra("brdgHouseLat", 0);
longitude = data.getDoubleExtra("brdgHouseLong", 0);
Log.v(TAG, "and form has a lat = " + latitude);
Log.v(TAG, "and a long = " + longitude);
}
}
Needless to say I have goggled for solutions on this and have checked into my manifest (I haven't set any flags); fragments (no fragments here), etc.
Am starting to think that maybe SharedPreferences
will be a better option but am just puzzled of the inconsistency of the responses. Any help will be appreciated
========================================================================= Here are the three methods of the second activity relevant to this question:
@Override
public void onBackPressed() {
super.onBackPressed();
packLatLong();
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case android.R.id.home: {
packLatLong();
}
}
return (super.onOptionsItemSelected(menuItem));
}
private void packLatLong() {
if (latitude != 0 && longitude != 0) {
Log.v(TAG, "packing this lat = " + latitude);
Log.v(TAG, "packing this long = " + longitude);
Intent intent = new Intent();
intent.putExtra("brdgHouseLat", latitude);
intent.putExtra("brdgHouseLong", longitude);
setResult(RESULT_OK, intent);
finish();
}
}
Please note that pressing either the back button as well as the home button in the action bar triggers the packLatLong
method