App uses the 'old' database after downloaded the 'new' one

mc73

Well-Known Member
Licensed User
Longtime User
Hello,

I have an activity which downloads a new version of my database. When finished downloaded (and I can assure you that the new file is properly copied - I see its contents there, with another app), I close my app (just with activity.finish). User is supposed to reload the app, but then I realize that my app is still using the 'old' database. This thing is corrected, if Ι set my device to clear all its RAM contents. Then, we can read the new db. Now, I can understand that the cause of this, is that probably the OS is reading the db from its RAM contents, so I have to tell my clients either to clear RAM or to restart their device. Still, I find it weird. Using all sql.close commands, properly activity.finish to each activity, initializing the db in activity_create (I put a msgbox there, just to be sure that the initialization process, after the db update, is performed) and there it is the 'old' db, sitting in my RAM. Any idea or am I missing something here?
 

Djembefola

Active Member
Licensed User
Longtime User
B4X:
ExitApplication
instead of
B4X:
activity.finish
could be a solution in this case.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
sql object is closed.

Using all sql.close commands, properly activity.finish to each activity, initializing the db in activity_create (I put a msgbox there, just to be sure that the initialization process, after the db update, is performed) and there it is the 'old' db, sitting in my RAM. Any idea or am I missing something here?
Erel, this is not the problem, I've made all checks.
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
when you download the database do you replace the old database with the new one? or do you have both databases on the device at the same time?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
when you download the database do you replace the old database with the new one? or do you have both databases on the device at the same time?
The old is replaced by new. Proof, as I've already said: after I close the app and remove it from ram (or reboot), my app uses the updated database. By the way, just to be sure that I copy without problems, I firstly delete the old database. The app is keeping in temporary memory, data from the old. After restart, no problem!
OK, perhaps I should accept this is just the way Android OS works (I mean its activities life cycle) and advice users to restart after a serious download.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
How do you know it is the old database being used?
I populate a view from a table of users. It contains the old data, though I have cleared it, reinitialize it, and so on. If it was the new one, the populating process would read the new data. As I've said, it does so, if I clear RAM, which of course kills the process and restart the app.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
So closing the database and re-opening it gives the old data as well?
Exactly. IF I keep the app open. If I completely close it (terminate its process), it reads the new data. I spent a lot of time, checking and rechecking my populating sub routine. I was hoping I had a bug there. Nope.
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
are any updated from the application?

if you updated a table and then read back the data do you get the old information or the new?

my thought is that somehow it is being cached so if you were to do an update it should flush the cache
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Exactly, it is being cached. And cache is removed when the app terminates. I've tested all data tables, for other reasons. They all give the old data. It's ok, since program terminations does the trick, I can live with that. If, however, I notice a bug in my populating routine, I will surely inform you, since to me, it seems more like a bug in android's behavior, which I hope is not true.
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
i usually end my programs with exitapplication and appfinish - that usually forces the program out of memory totally - that should flush your cache
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
i usually end my programs with exitapplication and appfinish - that usually forces the program out of memory totally - that should flush your cache
This is quite true, my friend. I would use it, surely. It's just that exitApplication cause me some troubles in some of my apps, in their earlier stages. I try to avoid it, as much as possible. After all, there are just too many apps out there, requiring a reboot. One more in the list, wouldn't make much of a difference, would it? :)
 
Upvote 0
Top