I'd like to start my app and show the main screen instantly. Half of the info on the screen will be loaded form local storage and the other half will be from a web service. Each of these will be on two different fragments. I'd like to display a loading indeterminate progress bar while the data is being fetch from the webservice, similar to how the Google Play Store loads it's app date as shown below by the two states below:
My thoughts on implementing it are as follows:
Load the fragment in with the progress bar & the normal screen (hidden) in one layout. Once the data from the web service has been collected, populate the normal screen, then hide the view group containing the progress bar and show the viewgroup with the data.
Is this best practice? Are the better ways to do it than this?
Thanks in advance.
Need for onActivityCreated() deprecation In such similar fashion android developers saw the tight coupling of code dependent to the Activity's life cycle. And they decided that it is not a good practice anymore to be dependent on the activity attach to do certain things inside the fragment.
Such as listed below: onCreate - This method is called to initialize or add the fragment to the host activity. The layout is also inflated in this stage. All elements initialized in this method are usually preserved whenever the fragment is paused. onStart - In this step, the fragment is visible or active.
Add a fragment to an activity You can add your fragment to the activity's view hierarchy either by defining the fragment in your activity's layout file or by defining a fragment container in your activity's layout file and then programmatically adding the fragment from within your activity.
The onDestroyView() method is called after onStop() and before onDestroy() .
You can implement it yourself but you can also use a simple library called ProgressFragment avalaible on github
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With