Android Question Database file gets overwritten on app update

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Is there a way I can upgrade my apps and not have the database storage files get overwritten when I give them an update to their apps?

I'm not using the database directly but using the KeyValues library.
 

eps

Expert
Licensed User
Longtime User
Can you outline this a little more...

Is it the case that :

Ver 1.0 DB included, User installs App, DB gets moved to the read/write area for the App involved.

User adds some data.

Ver 2.0 DB included, User installs App, DB gets moved to the read/write area for the App involved.

All User data is effectively removed.

There are a number of different ways of handling this.

You could write the data to a file as well as the DB, so that when the App gets upgraded you capture this fact in your App and then re-add all the User data as well. This becomes a little more tricky if the User can add and remove data, but hopefully you get the idea. I do this for one of my Apps, but the User doesn't really add data in my App, they just indicate that records contained on one table are also on another table, their Favourites.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi,

Thanks for the replies. With the help of Margret I changed my coding to this and it did not wipe out the data:

B4X:
If FirstTime Then' This is the first time the app was run since installation.



' Show the user an hourglass while everything loads.

'------------------------------------------------------------

Activity.LoadLayout("PleaseWait")



PanelPleaseWait.Visible = True


DoEvents



' Set up default configuration settings.

'---------------------------------------

kvConfigurationSettings.Initialize(File.DirDefaultExternal, "kvConfigurationSettings", 1)

kvConfigurationSettings.PutSimple1("UserStoppedService", 0, "No")


' The data for the periods is stored as 9 items for each period.

' This will be loaded into a list the user can alter.

' Key: Period number 1, 2, etc.

' Index 0: Period description.

' Index 1: Period start time.

' Index 2: Peroid end time.

' Index 3: Day of week (Mon) active or inactive.

' Index 4: Day of week (Tue) active or inactive.

' Index 5: Day of week (Web) active or inactive.

' Index 6: Day of week (Thu) active or inactive.

' Index 7: Day of week (Fri) active or inactive.

' Index 8: Day of week (Sat) active or inactive.

' Index 9: Day of week (Sun) active or inactive.

'---------------------------------------------------------------


kvSchoolPeriods.Initialize(File.DirDefaultExternal, "kvSchoolPeriods", 10)



If File.Exists(File.DirDefaultExternal, "kvSchoolPeriods") = False Then



kvSchoolPeriods.PutSimple1("0", 0, "")

kvSchoolPeriods.PutSimple1("0", 1, "")

kvSchoolPeriods.PutSimple1("0", 2, "")

kvSchoolPeriods.PutSimple1("0", 3, "Active")

kvSchoolPeriods.PutSimple1("0", 4, "Active")

kvSchoolPeriods.PutSimple1("0", 5, "Active")

kvSchoolPeriods.PutSimple1("0", 6, "Active")

kvSchoolPeriods.PutSimple1("0", 7, "Active")

kvSchoolPeriods.PutSimple1("0", 8, "Inactive")

kvSchoolPeriods.PutSimple1("0", 9, "Inactive")



kvSchoolPeriods.PutSimple1("1", 0, "")

kvSchoolPeriods.PutSimple1("1", 1, "")

kvSchoolPeriods.PutSimple1("1", 2, "")

kvSchoolPeriods.PutSimple1("1", 3, "Active")

kvSchoolPeriods.PutSimple1("1", 4, "Active")

kvSchoolPeriods.PutSimple1("1", 5, "Active")

kvSchoolPeriods.PutSimple1("1", 6, "Active")

kvSchoolPeriods.PutSimple1("1", 7, "Active")

kvSchoolPeriods.PutSimple1("1", 8, "Inactive")

kvSchoolPeriods.PutSimple1("1", 9, "Inactive")



kvSchoolPeriods.PutSimple1("2", 0, "")

kvSchoolPeriods.PutSimple1("2", 1, "")

kvSchoolPeriods.PutSimple1("2", 2, "")

kvSchoolPeriods.PutSimple1("2", 3, "Active")

kvSchoolPeriods.PutSimple1("2", 4, "Active")

kvSchoolPeriods.PutSimple1("2", 5, "Active")

kvSchoolPeriods.PutSimple1("2", 6, "Active")

kvSchoolPeriods.PutSimple1("2", 7, "Active")

kvSchoolPeriods.PutSimple1("2", 8, "Inactive")

kvSchoolPeriods.PutSimple1("2", 9, "Inactive")

EndIf



' This is the main menu screen.

'------------------------------

LoadMainLayout
 
Last edited:
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi,

The user of the app saves the school period details and that's stored in the database. I updated the database and re-installed the app and the new updated data was still there when I viewed the data within the app.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
No worries, but beware if you need to change the database structure or add a new table or column for instance. You will then need to try and manage that, but it might never happen for your software :)
 
Upvote 0
Top