问题
I have an activity that launches another one using startActivityForResult. This step is ok. Then the second activity has a map and when a button is clicked the geopoint coordinates are passed to a bundle that is used on first activity to fullfil an EditText. The function onActivityResult is runned until the end and then the program crashes and appears a message with "Source not found" on screen.
This is the function on mapActivity:
public void ConfirmLoc(View v){
double lat = loc.getLatitudeE6()/1E6;
double lng = loc.getLongitudeE6()/1E6;
Intent ievloc = new Intent();
Bundle bevloc = new Bundle();
bevloc.putDouble("latitude",lat);
bevloc.putDouble("longitude",lng);
ievloc.putExtras(bevloc);
setResult(RESULT_OK,ievloc);
finish();
}
And this is the onActivityResult on first Activity:
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode==1){
if(resultCode==RESULT_OK){
EditText loc= (EditText) findViewById(R.id.LocalizacaoEvento);
bevloc = data.getExtras();
if(bevloc!=null){
String latitud = String.valueOf(bevloc.getDouble("latitude"));
String longitud = String.valueOf(bevloc.getDouble("longitude"));
loc.setText(latitud+" , "+longitud,TextView.BufferType.EDITABLE);
}
}
else if(resultCode==RESULT_CANCELED){
}
}
}
Can anyone help? thanks
回答1:
You need to add the @Override line on top of your onActivityResult method. When you do this, you will also be adding the following line as the first line of the method:
super.onActivityResult(requestCode, resultCode, data);
Also ensure that your compiler settings is 1.6 and not 1.5 as by default in Eclipse.
来源:https://stackoverflow.com/questions/13987362/onactivityresult-error