Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Loading fragment implementation

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:

State 1 & State 2 (Google Play Store)

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.

like image 951
Gyroscope Avatar asked Nov 08 '13 08:11

Gyroscope


People also ask

Why onActivityCreated is deprecated?

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.

Which method is used to load fragments?

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.

How do I load an activity fragment?

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.

Is onDestroyView always called?

The onDestroyView() method is called after onStop() and before onDestroy() .


1 Answers

You can implement it yourself but you can also use a simple library called ProgressFragment avalaible on github

like image 106
souleymane sidibé Avatar answered Sep 22 '22 03:09

souleymane sidibé