I am using SQLite and have one local database file for storing short text messages. In the .db file there are several tables. I have one Activity and one sticky Service, which is for intercepting SMS.
My issue is I need to access the database to record the new arriving message when it is intercepted by the Service. But at the same time I also need to access the db file in order to display records / refresh the user's main interface (if they are working with the app) --> Something looks like a chat application (you are viewing the main Activity while new message can come at any time and you have to record it in the background, then update it immediately in the main Activity). The situation is even worse when user wants to delete an old message (I have to delete it from the database), at the same time a new one can come (I have to access the database to record it) etc.
My app can run well, but sometimes I got unpredictable error ("locked database error"), sometimes my app reacts unpredictably, sometimes it hangs for long time...
I guess it is because the background recording of new message is not finished yet but the app try to access the database in order to refresh the interface. So you have multiple accesses at the same time.
What is the correct strategy I should do for my case? Thanks for your advice.
Regards,
bsnqt
My issue is I need to access the database to record the new arriving message when it is intercepted by the Service. But at the same time I also need to access the db file in order to display records / refresh the user's main interface (if they are working with the app) --> Something looks like a chat application (you are viewing the main Activity while new message can come at any time and you have to record it in the background, then update it immediately in the main Activity). The situation is even worse when user wants to delete an old message (I have to delete it from the database), at the same time a new one can come (I have to access the database to record it) etc.
My app can run well, but sometimes I got unpredictable error ("locked database error"), sometimes my app reacts unpredictably, sometimes it hangs for long time...
I guess it is because the background recording of new message is not finished yet but the app try to access the database in order to refresh the interface. So you have multiple accesses at the same time.
What is the correct strategy I should do for my case? Thanks for your advice.
Regards,
bsnqt