onActivityResult()未在片段中调用

时间:2014-05-22 14:17:38

标签: android android-fragments android-tabhost

我有MainActivitytabhostfragment。来自startActivityForResult的{​​{1}},在该活动完成任务后,我执行fragment并将生成的控件返回到上一个片段。我已经探讨了答案herehere。但它们似乎都不适合我。

以下是我的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结束后没有一种方法可以调用。

1 个答案:

答案 0 :(得分:-1)

尝试getActivity().startActivityForResult()