Reputation: 7062
An Android application has two activities.
Activity A shows a list of items. Activity B shows some details about a particular item.
The details are loaded from a largish SQLite database. The queries used to generate the data take about 250 to 500milliseconds on a reasonable phone.
My question is what is the best practice for loading the data while providing a nice user experience.
Currently Activity B executes an AsyncTask when it's created. When the task completes it creates a number of views and adds them to the screen. No data is loaded on the UI thread.
To the user Activity B opens with the nice standard zoom animation and then a fraction of a second later the view populates with data. It looks a little crap IMO.
Another option is to load the data on the UI thread. If I do this at the right time then the screen freezes with the list item selected for 250ms while the data loads and then the view changes with the standard zoom animation but it's zooming into an already populated view. It looks a lot nicer but I am blocking the UI thread which is not ideal.
What is the best way to achieve a nice transition when the new view isn't ready yet?
Upvotes: 0
Views: 2015
Reputation: 109247
Either put a progress dialog
for loading data task and if you don't then..
You can use onProgressUpdate()
method of your AsyncTask
for intervally update your resulted data from database to UI..
protected void onProgressUpdate(Integer... progress) {
//this runs in UI thread so its safe to modify the UI
myTextField.append("finished call " + progress);
}
•onProgressUpdate
– called whenever publishProgress is called from the background task, used to report progress back to the UI.
Also you can use LIMIT
and OFFSET
clause of sqlite database
for fetching data from database with bound number of returned result in your select query
for fetching large amount of data from database..
Example:
Select * from Animals LIMIT 100 OFFSET 50
Upvotes: 2