0

I have created an application and service. These two app uses single DB which has been placed on SDCard. My Service will look for new data and push those to server for every 30 sec. Meanwhile user uses my Application for entering some data/records in db. Its working fine, if the network is good but if the network fails my application is failing to insert the records to db as Service is waiting for response from Server. I have used Singleton class to rectify my mistake even though i am facing the same issue. How to overcome this? Need help Guys

Kalai.G
  • 1,610
  • 13
  • 22
  • i think u need to write a content provider for your database,through content provider u can easily perform al;l database operations on a database – Farhan Munir Dec 30 '13 at 07:35
  • content provider cannot be used for the db which is presented outside the sdcard – Kalai.G Dec 30 '13 at 09:15

2 Answers2

1

You are basically saying that one thread cannot store data into SD-card just because another is busy talking with some remote web server. Why?

It seems that some synchronization lock from the network access thread is unnecessarily broad, you lock the database when this is not required. Move network access code outside you synchronized statements or methods that put a lock on the database, try to start and finish with the database as soon a possible without other activities in between.

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
  • exactly the same. Actually i need to check for the new data whether its updated to server or not. So i am opening the DB for every 30 sec which is locking the db if there is fail in response from server. Any tuts to follow? – Kalai.G Dec 30 '13 at 09:14
  • Talk with remote server through the network before opening the DB. Only open DB after you already have the response. – Audrius Meškauskas Dec 30 '13 at 09:22
  • Does not matter is your network good, bad or off, just finish with it before you start working with the database. – Audrius Meškauskas Dec 30 '13 at 12:30
  • The problem is because of parallel execution. Sqlite is not thread safe it seems http://stackoverflow.com/questions/6675240/is-sqlite-database-instance-thread-safe – Kalai.G Dec 31 '13 at 05:42
0

There is nothing you can do against having a bad internet connection. Put a timeout limit on your http requests and re-try later (or listen for connectivity changes).

Next time, try to keep your question title relevant to your question. At the moment, it has nothing to do with eachother. You're not using 2 applications and the problem isn't in using the db from 2 applications.

Stefan de Bruijn
  • 6,289
  • 2
  • 23
  • 31