This question comes from an issue I am having, or really confusion on something. So its frowned upon to query databases on the UI thread. But my issue is, what if what appears on the screen relies on what the result is. Should you still run it in the background, or should you halt the screens output until you know the info you need from the database?
Share
The way you should set it up is to use an
AsyncTaskto query the database, using thedoInBackgroundmethod. Then use theonPostExecutemethod to update the UI. You can’t update the UI on any other thread than the main thread.Hope that makes sense. If not, here are a couple articles that might help:
http://android-developers.blogspot.com/2009/05/painless-threading.html
http://developer.android.com/reference/android/os/AsyncTask.html
http://www.peachpit.com/articles/article.aspx?p=1823692&seqNum=3
Best of luck!