onActivityResult error

荒凉一梦 提交于 2020-01-06 08:23:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!