英文:
How to refresh all activity from one activity
问题
我有多个带有各自活动的片段。
当我在MainActivity中进行刷新时,我希望所有片段的活动也能刷新。因为我在与数据库一起工作,这涉及到刷新其他片段以更新数据。
MainActivity.kt
swipeRefresh.setOnRefreshListener {
// 仅刷新MainActivity
// 我不知道如何在此处调用片段的活动
swipeRefresh.isRefreshing = false
}
英文:
I have multiple fragments with its activity.
When I refresh in MainActivity, I want all fragment's activity to refresh as well. Because I work with database and it involves refreshing others fragments to update the data.
MainActivity.kt
swipeRefresh.setOnRefreshListener {
// refreshing MainActivity only
// I don't know how to call fragment's activity here
swipeRefresh.isRefreshing = false
}
答案1
得分: 0
片段(Fragment)依赖于活动(Activity),而活动(Activity)不依赖于片段(Fragment)。您在活动中所做的操作会影响到片段(Fragment)。以此作为起点进行查找。
英文:
Fragment is dependent on activity and activity is not dependent on fragment. What you do in activity will affect the fragment. Do use this a starting point to look up.
答案2
得分: -1
在活动中,您可以调用 recreate()
方法来重新创建活动 (API 11+),或者您可以在活动内部使用以下方法来刷新活动。
finish();
startActivity(getIntent());
英文:
In the activity, you can call recreate()
to "recreate"
the activity (API 11+)
or you can use this for refreshing an Activity from within itself.
finish();
startActivity(getIntent());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论