1

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..

Community
  • 1
  • 1
faizanjehangir
  • 2,771
  • 6
  • 45
  • 83

1 Answers1

-1

try getActivity().startActivityForResult()

f.old
  • 343
  • 3
  • 15
  • Not working. This is how I am setting my intent for `activity`: `Intent intent = new Intent(getActivity(), MovieDetail.class);` – faizanjehangir May 22 '14 at 15:42
  • On updating your answer to account for the OPs info, you might also enhance it to explain *why* your solution works. This will help people finding your answer later. – mabi May 22 '14 at 16:06