最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - How to know if fragment is recreated after back press and popBackStack()? - Stack Overflow

programmeradmin5浏览0评论

I have a two fragments, A and B. Let say fragment A is a person form and B is a city searcher.

In fragment A, I query the database server for some data, and until I get this info I display a ProgressBar. Once all data is available and set to each of the form fields in the layout, I set the ProgressBar to GONE.

From fragment A, user can open fragment B (I use FragmentTransaction.replace()) to search for the city. However, when the user press back or choses a city (I close fragment B using FragmentManager.popBackStack()) and gets back to fragment A, the view of fragment A is created again, so the ProgressBar is visible.

Since I already loaded all information from the server, my code doesn't reach the section where I set the ProgressBar visibility to GONE.

Ideally, when creating fragment A view again savedInstanceState shouldn't be null (I save some stuff in onSaveInstanceState()), so in that case I could hide the ProgressBar, but savedInstanceState is always null.

Is there anyway to know from fragment A if view is being recreated because user is back after closing fragment B? I can only think about creating a variable to control if ProgressBar should be displayed...

发布评论

评论列表(0)

  1. 暂无评论