I am using sql lite and i am usually querying 1 table. Is it bad if I do the querying from the main ui thread?
Thank you
It depends. If your table is really big, it could take time to execute the query, and possible cause a noticeable lag in your app. Also, you say that you usually query only one table, so that's leaves the possibility of more queries on additional tables.
As a general rule, I do a lot of work like querying and downloading in background threads using AsyncTasks, as even if they do not take very long now, it gives me extra freedom later on to expand the app without extensive rewriting.
Yes, actually it is bad to query from main UI thread.
http://android-developers.blogspot.com/2009/05/painless-threading.html
It is not too bad if it takes less than one or two seconds, but it's always recommended to do it on another thread.
Please read the Android article Designing for Responsiveness
Potentially long running operations such as network or database operations, or computationally expensive calculations such as resizing bitmaps should be done in a child thread (or in the case of databases operations, via an asynchronous request).
The article continues to describe that performing expensive operations on the main thread can lead to an "Application Not Responding" error and the OS will kill your app.
So while you can perform these operations on the main thread, it is best to use background threads.
yes, you can provided your query should not take long time other wise it is better to use Async task for this