-2

I have a Fragment containing a RecyclerView. I am starting an Intent to a new Activity from this Fragment. Now I want to add some new data in DB from this Activity and update my RecyclerView in Fragment when the Activity is finished. I know that onActivityResult() method will work in Activity only. Is there any way to achieve this in Fragment?

2 Answers2

0

you can get that callback in fragment also.. just startActivityForResult from fragment. and override onActivityResult() in both activity and fragment. just dont use super in activity so that it will redirect you to your fragment method.

AJay
  • 1,233
  • 10
  • 19
0

You just need to override onActivityResult a handler method in fragment, it will automatically get called from activity. In latest implementation of SDK it automatically forwards to fragment see here

Nayan Srivastava
  • 3,655
  • 3
  • 27
  • 49