Can't return data to parent activity
- by user23
I'm trying to return data (the position of the item picked from the grid) to parent activity, but my code fails. The debbuger shows how 'data' gets right the key and data in the "data.putExtra("POS_ICON", position)" at child activity, but after in onActivityResult() at parent activity the debbuger shows 'data' with no key nor data returned...it's like if data loses its content. I've followed other posts and tutorials but no way. Please help.
Parent activity:
public void selIcono(View v){
Intent intent = new Intent (this, SelIconoActivity.class);
startActivityForResult(intent,PICK_ICON_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode,
Intent data) { //here's the problem: no data is returned!!
if (requestCode == PICK_ICON_REQUEST) {
if (resultCode == RESULT_OK) {
// An icon was picked.
putIcon(data.getIntExtra("POS_ICON", -1));
}
}
}
Child activity:
public class SelIconoActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sel_icono);
GridView gridview = (GridView)findViewById(R.id.gr_iconos);
gridview.setAdapter(new ImageAdapter (this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent data = new Intent();
data.putExtra("POS_ICON", position);
setResult(Activity.RESULT_OK, data);
finish();
}
});
}
}