开发者

When to load database data into an adapter

I have a simple personal application I'm working on that queries some records in an SQL Database and populates an adapter for a listview and is basically working fine... but I've began to wonder if I'm doing certain things at the right point of the framework.

Currently I'm loading everything up during onCreate(). In theory, I could be loading up quite a bit of data, so I wanted to possibly throw up a ProgressDialog while the information is being added to the adapter, but I ran into some odd threading issues with the Cursor. Ultimately, I launched a Progress Dialog near the end of onCreate(), followed by sleeping on another thread and calling a method to load my data with runOnUiThread() following the short sleep time, having the end of that method dismiss the Progress Dialog.

This works, but it's brought me to 开发者_StackOverflow社区whether or not I should be loading database data during onCreate... or whether it should be moved to onStart() or onResume(), adding in code to clear the close and open the database, clear and repopulate the adapter as necessary as other Activity's are started and finished. Or would all that be unnecessary and I should just keep the adapter populated during onCreate()?


Reto Meier's suggestion to use an Application may suit your needs. Take a look at Activity restart on rotation Android


Move it to onResume, as if you stop the activity you can destroy the adapter and fill it back when to resume the activity. It helps to save memory and also helps to update the adapter if data has changed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜