I am working on an application which populates a listfragment with data from the internet. The contents of the list often changes based on what tab the user is currently viewing and extra items are appended to the list when the user reaches the end (pagination).
Currently the listfragment is based on an arrayadapter. The contents of the adapter get cleared when a user changes tabs and new items are then added. When the user reaches the end of a list more deals are added to the current adapter.
There are multiple problems with the current implementation.
1. Occasionally when users restart the application data is downloaded from the internet successfully but the list remains empty. This tends to happen after you have launched the application and then used many other applications, before coming back to this application. The only way to get the application back to a working state is to force close the application.
2. By default when the screen is rotated Android create the view again with oncreate, which downloads the data again from the internet.
Currently to overcome this I handle rotation change myself (using onConfigurationChanged() ), which I know is not the preferred way.
So how should I best store the arraylist which backs the arrayadapter, baring in mind I need to update it frequently. I also need to store the contents of the arraylist during rotation change.
Please let me know if any current code would be helpful.
1 Answer