gpt4 book ai didi

android - 关闭 Activity 后如何刷新以前的 fragment ?

转载 作者:行者123 更新时间:2023-11-29 01:38:28 32 4
gpt4 key购买 nike

我有一个 fragment 可以抛出一个 Activity ,用户可以在其中插入一些细节。当用户终止填充数据时, Activity 关闭。然后显示上一个 fragment ,我希望更新它(使用用户在 Activity 中提供的数据)。

如果它是一个 Activity ,而不是 fragment ,我可以使用这个:

@Override
public void onResume(){
super.onResume();
recreate();
}

如何对 fragment 做同样的事情?

最佳答案

您将在该 Fragment 所属的 Activity 中覆盖 onResume,并在该 Activity 中重新创建(重新启动)该 Fragment。例如

public class ActivityA extends Activity {
@Override
public void onResume() {
// here you can get the Fragment instance , so you can recreated this fragment here or invoke this fragment's function to set data or refresh data
}
}

关于android - 关闭 Activity 后如何刷新以前的 fragment ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26377907/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com