open a database using Android and MVC
I'm writing an Android application, a dictionary just for fun. I've decided to use MVC as architectural pattern. I need to do many queries because I want to c开发者_Go百科reate an istant searching like Google does: Every time the user add a letter to the EditText
I want do query the database.
What do you think about this logical and perfomant problem?
If we're talking purely on the theoretical pattern design, the truth is that the Model probably shouldn't even expose the fact that it's getting it's data from a database. You can easily keep track internally in the model of whether the database is open or not and open it when necessary.
On the performance aspect of the question, when it comes to questions like this, the only way to get a good answer is to measure. It could be that keeping the database open won't have any ill effects and you won't have any problems just keeping it open. That will be the easiest and fastest solution more than likely. However, it could be that keeping it open might take up too much memory, or keep the CPU busy, or some other side effect.
As I mentioned, the only way to really have a definitive answer is to measure. You can use DDMS, amongst other profiling tools.
精彩评论