I have a MainActivity
, tabhost
and a fragment
. I startActivityForResult
from fragment
, after completion of task in that activity, I do a finish
and return the resulting control to the previous fragment. I have explored the answers here and here. But none of them seem to work for me.
Here is how my fragment
code:
images[j].setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getActivity(), MovieDetail.class);
intent.putExtra("movie", movieObj);
startActivityForResult(intent, 1);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
Log.v("activity result", "called");
if (requestCode == 1) {
if(resultCode == getActivity().RESULT_OK){
if (data.getBooleanExtra("movieDeleted", true)){
TabMovies.refresh();
}
// refresh();
}
if (resultCode == getActivity().RESULT_CANCELED) {
//Write your code if there's no result
}
}
}
Finish activity
:
Intent returnIntent = new Intent();
returnIntent.putExtra("movieDeleted",true);
setResult(RESULT_OK,returnIntent);
finish();
This is my MainActivity
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
Log.v("parent", "called");
super.onActivityResult(requestCode, resultCode, data);
}
I am also giving a super
call to onActivityResult()
in MainActivity
. But none of the methods is getting calling after the activity
ends..