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
?
Asked
Active
Viewed 155 times
-2

Jasmine Thomas
- 9
- 7
-
Yes in fragment you can also achieve. – Piyush Jan 18 '17 at 05:47
-
Do you know `EventBus` in Android ? Go with that – M D Jan 18 '17 at 05:55
-
@MD Yes I know _EventBus_ – Piyush Jan 18 '17 at 06:01
-
`I know that onActivityResult() method will work in Activity only.` you are wrong about this. `onActivityResult` works just file in fragment. – Vladyslav Matviienko Jan 18 '17 at 06:04
-
Have you read this? http://stackoverflow.com/questions/6147884/onactivityresult-is-not-being-called-in-fragment?rq=1 – K.Sopheak Jan 18 '17 at 06:23
2 Answers
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