-1

Initially we had activity for our app,on that we have return value from activity to activity using onActivityResult. But now we are changing into fragment,but we are not getting the return value between fragment. Is there is any solution for onActivityResult between fragment.

Satheeshkumar
  • 452
  • 4
  • 13
  • What do you mean by "between fragment"? – Mike M. Nov 19 '15 at 11:47
  • Possible duplicate: http://stackoverflow.com/questions/17085729/startactivityforresult-from-a-fragment-and-finishing-child-activity-doesnt-c – Kuffs Nov 19 '15 at 11:50
  • and another: http://stackoverflow.com/questions/6147884/onactivityresult-not-being-called-in-fragment – Kuffs Nov 19 '15 at 11:51
  • Search is the box at the top – Kuffs Nov 19 '15 at 11:51
  • @Mike M: I have only one Activity as a Base for entire application and implemented swipe menu. In that there is a communication need to happen between a sub fragment and the Fragment residing on the current view. That's what I said as between fragments. – Satheeshkumar Nov 19 '15 at 12:45
  • @Kuffs: Thank you for your updates. I will not looking the same which you suggested. I also know the search box is on top. – Satheeshkumar Nov 19 '15 at 12:46
  • Possible duplicate of [How to pass data between fragments](http://stackoverflow.com/questions/5194548/how-to-pass-data-between-fragments) – Mike M. Nov 19 '15 at 12:56
  • @Mike: No mike we could not pass directly to that fragments, that is a tab fragment inside a base fragment . That base fragment is attached to the Base activity. – Satheeshkumar Nov 20 '15 at 04:54
  • Same basic method. Implement interfaces to communicate between the base Activity and the base Fragment, and between the base Fragment and the tab Fragment. – Mike M. Nov 20 '15 at 05:07

1 Answers1

1

yes there is a solution:

on your activity: Don't do anything. If you for some reason absolutely needs to, you must always call super like following.

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
}

then, your Fragments, you call:

public void doSomethingThatNeedsActivityResult(){
    startActivityForResult(intent, YOUR_FRAG_REQUEST_CODE)
}

@Override
public void onActivityResult (int requestCode, int resultCode, Intent data){
   if(requestCode == YOUR_FRAG_REQUEST_CODE){
       // here the result
   }
}

important to notice is that you should not call getActivity().startActivityForResult(...) it must be called using the fragment specific method.

Budius
  • 39,391
  • 16
  • 102
  • 144