Android Question where to save database and delete

3394509365

Active Member
Licensed User
Longtime User
I am making an app that has a starting database, which installs the app together.

The user can then of course populate it with tables etc.

Then at the time of installation a folder is created that will contain photos.

I have doubts:

1- in which part of the memory should I save the database and the folder? (if the app is uninstalled from the db what will happen? the folder what will happen?)

2- could I ask during uninstallation whether to delete or leave both the db and the folder, for example during the app update or operating system update?

Thank you
 

Peter Simpson

Expert
Licensed User
Longtime User
@3394509365

B4X:
Sub Process_Globals
    Public DBName As String = "Test.db"
    Public RP As RuntimePermissions   
    Public SafeDirectory As String
...

Sub Service_Create
    SafeDirectory = RP.GetSafeDirDefaultExternal("")
  
    If File.Exists(SafeDirectory, DBName) = False Then
        Wait For (File.CopyAsync(File.DirAssets, DBName, SafeDirectory, DBName)) Complete (Success As Boolean) 'File.DirInternal
        ToastMessageShow($"DB Copied = ${Success}"$, False)
      Log("Success: " & Success)
    End If
...

Now you can safely use your SQLite database from anywhere in your app...
 
Upvote 0

3394509365

Active Member
Licensed User
Longtime User
thanks

But does this happen when I install the app? or when is it uninstalled?

I imagine, when it is installed, but if it is uninstalled do I lose all the changes made by the user?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

3394509365

Active Member
Licensed User
Longtime User
I intend to save the database on an external support maybe even an sd. in order not to lose the changes made up to that point especially in case of reinstallation.

Then I could make the database put it in DirInternal and if eventually the user wants to make a copy, maybe he does it on a sd (I have to give him some possibilities).
Then I create the folder that will contain the Photos / songs in a folder in DirRootExternal, which at the time the app is uninstalled will remain on the device and if he wishes he will delete them. It could be an idea ?
 
Last edited:
Upvote 0

Polaris

Member
Licensed User
I intend to save the database on an external support maybe even an sd. in order not to lose the changes made up to that point especially in case of reinstallation.

Then I could make the database put it in DirInternal and if eventually the user wants to make a copy, maybe he does it on a sd (I have to give him some possibilities).
Then I create the folder that will contain the Photos / songs in a folder in DirRootExternal, which at the time the app is uninstalled will remain on the device and if he wishes he will delete them. It could be an idea ?


What you are asking is : How can I backup all the data (Photos/Songs , DB, etc so that if the app user reinstalls the app no data is lost and the user can carry on where he left off.

What you need to consider is why would the user reinstall your app ? Reinstalling mostly happens when a user upgrades to a new device, either because he wants a newer phone or his previous phone was lost /stolen. Either way your backups onto internal memory of the old device are not going to be of much use.

OliverA suggested you try Android Auto Backup for apps, and this could be a good solution, but I haven't seen any project in the forum that has implemented it so you'll have to try to get to work by yourself. ( Maybe Erel can come up with a small demo project that implements Auto Backup to help the less experienced ) However Auto Backup is oriented towards storage of user data , not files like jpeg, mpeg, or pdf. Actually it will work with these and most other files, the problem is the cloud space allocated is 25 MB , so with jpeg and mpeg etc you're going to run out of space fast. Apart from this Auto Back is a great solution for data like DBs and user preferences, because it is fully automated , and does all the work by itself in the background without annoying the user, and if he upgrades to a new device and reinstalls all the old data is there like nothing happened.

I have this exact problem with an app I'm working on, it's a business app and can end up holding 100-200 pdf files, which the user CANNOT lose no matter what happens, so my app must backup data twice daily , and it must be to some place other then the users device, so in case of loss or theft all the data and documents are retrievable. This can be done to the users google cloud storage which every android user gets for free (15Gb if I remember correctly) However I found no way to automate the backup process to Google Cloud Storage, it would have to be done manually every day by the user, and that is not really a good option. This would be the best solution by far if I could get the process fully automated.

In the meantime the solution I have is a backup app, which is a second app the user can download to another device and which basically acts as a backup server. It takes one minute to configure the server app , then two apps connect twice a day and the backup process executes fully automated with no hassles for the user . The biggest hurdle here is that you need one device to know the IP address of the other , and with dynamic IP they will periodically change . So you every time the IP address changes you need to let the other device know what the new IP is . But that's another story ...........?
 
Upvote 0
Top