[英]Is there any way to call onActivityResult() method to return data from Activity in Fragment?
I have a Fragment
containing a RecyclerView
.我有一个包含RecyclerView
的Fragment
。 I am starting an Intent to a new Activity
from this Fragment
.我正在从此Fragment
开始一个新Activity
的意图。 Now I want to add some new data in DB from this Activity
and update my RecyclerView
in Fragment
when the Activity
is finished.现在我想从这个Activity
在 DB 中添加一些新数据,并在Activity
完成时更新Fragment
RecyclerView
。 I know that onActivityResult()
method will work in Activity
only.我知道onActivityResult()
方法只能在Activity
工作。 Is there any way to achieve this in Fragment
?有没有办法在Fragment
实现这一点?
you can get that callback in fragment also.. just startActivityForResult
from fragment.您也可以在片段中获得该回调......只需从片段startActivityForResult
。 and override onActivityResult()
in both activity and fragment.并在活动和片段中覆盖onActivityResult()
。 just dont use super in activity so that it will redirect you to your fragment method.只是不要在活动中使用 super ,以便它会将您重定向到您的片段方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.