I have done this before with no problem, so I am probably missing something silly.
I am trying to start a secondary activity that creates a new Owner in my database and returns the owner's id.
In my first activity i am calling the second like so:
Intent new_owner = new Intent(this, AddOwnerActivity.class);
startActivityForResult(new_owner, REQUEST_NEW_OWNER, null);
overridePendingTransition(R.anim.slide_in_bottom, R.anim.abc_fade_out);
Then in my second Activity i am setting the result like so:
Intent data = getIntent();
Log.v("OWNER", "DATA sending: "+new_owner.getId()); // this logs a number like 13
data.putExtra("owner_id", new_owner.getId() );
setResult(RESULT_OK,data);
onBackPressed();//this calls finish();
Finally in my first Activity my onActivityResult looks like this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQUEST_NEW_OWNER && resultCode == RESULT_OK && data!=null){
Bundle bundle = data.getExtras();
super.onResume();
Log.v("OWNER", "DATA received: " + bundle.getInt("owner_id"));//this is ALWAYS LOGGING 0
selectOwnerWithId(bundle.getInt("owner_id"));
}
}
I can see my new owner being created in the Database successfull and in my secondary activity it is logging the right id when i set result, but my first activitity is ALWAYS logging 0 as the extra..
I have to be missing something small.. a second pair of eye would be appreciated
Aucun commentaire:
Enregistrer un commentaire