简体   繁体   中英

Is there any way to call onActivityResult() method to return data from Activity in Fragment?

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 ?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM