我有MainActivity
,tabhost
和fragment
。来自startActivityForResult
的{{1}},在该活动完成任务后,我执行fragment
并将生成的控件返回到上一个片段。我已经探讨了答案here和here。但它们似乎都不适合我。
以下是我的finish
代码:
fragment
完成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
}
}
}
:
activity
这是我的Intent returnIntent = new Intent();
returnIntent.putExtra("movieDeleted",true);
setResult(RESULT_OK,returnIntent);
finish();
:
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);
}
向super
发出onActivityResult()
来电。但是MainActivity
结束后没有一种方法可以调用。
答案 0 :(得分:-1)
尝试getActivity().startActivityForResult()