Android Question Is there a way to store data/DB files so that even when the app is uninstalled, the data is not deleted?

Daica

Active Member
Licensed User
In my app, I store data in an Sqlite file and then upload this data to the server.
Sometimes the user would uninstall the app and then reinstall again when they run into an issue.

When they uninstall the app, all data is lost.

Where can I store the DB file so that even when the user uninstall the app, the data is still kept, so that when they install the app again, that data gets uploaded?

I have SOME flexibility since the app is not on the playstore, and I don't have to target the latest API version.
 

JohnC

Expert
Licensed User
Longtime User
If you don't need to target a recent API version, then you should be able to use File.DirRootExternal to store the database in a sub-directory of the external memory on the users device that will persist between app uninstall/install.

...or you could add a "Export" feature to your app that can save/email a copy of the database to a folder not part of the app. Then have the user "Import" it after reinstalling your app.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I store data in an Sqlite file and then upload this data to the server.
If you have a copy of the data stored on a server then cannot you retrieve it from there? That is what I normally do these days to avoid the complications with using external storage on the 'phone.
 
Upvote 0

Daica

Active Member
Licensed User
If you have a copy of the data stored on a server then cannot you retrieve it from there? That is what I normally do these days to avoid the complications with using external storage on the 'phone.

The user creates the data locally and then it is sent to the server. I store it in a local Sqlite DB so that in the event where the phone crash or they lose reception, the data is not lost. However, if the app is reinstalled, the data is gone.
 
Upvote 0

Daica

Active Member
Licensed User
If you don't need to target a recent API version, then you should be able to use File.DirRootExternal to store the database in a sub-directory of the external memory on the users device that will persist between app uninstall/install.

...or you could add a "Export" feature to your app that can save/email a copy of the database to a folder not part of the app. Then have the user "Import" it after reinstalling your app.

Do you know what the latest API version I can use File.DirRootExternal with?

As for the "export" option, my users are people that are not very good with technology (elderly), so the less things they need to do, the better for them.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
In my app, I store data in an Sqlite file and then upload this data to the server.
Sometimes the user would uninstall the app and then reinstall again when they run into an issue.

When they uninstall the app, all data is lost.

Where can I store the DB file so that even when the user uninstall the app, the data is still kept, so that when they install the app again, that data gets uploaded?

I have SOME flexibility since the app is not on the playstore, and I don't have to target the latest API version.
... I am sorry... you said that you are uploading the data...

Why not checking and giving the possibility to user to download the data to the default app data folder before create new data file... ???


//but the question here... is how you uploading the data... if for example you are uploading the sqlite file to google drive or at a ftp... will be super easy...
 
Upvote 0

Daica

Active Member
Licensed User
... I am sorry... you said that you are uploading the data...

Why not checking and giving the possibility to user to download the data to the default app data folder before create new data file... ???


//but the question here... is how you uploading the data... if for example you are uploading the sqlite file to google drive or at a ftp... will be super easy...

Yes, I am uploading the data, however, some of the users are not in a good location so sometimes the upload will fail.
There is also possibility of the phone rebooting, losing power, etc.
The data stays on the phone until the upload to the server is complete, and then I remove the data locally.

I mention in my previous post that the users using the apps are elderly and they are not very good with technology. They would not know what to do if I give them the option to select a folder to store the DB file.

I am uploading the data using a simple httpjob and uploading it to my server that runs PHP. I am uploading the entire Sqlite file, once the PHP server gets the file, I have scripts that go through the DB and grab what I need and store it on the server-side.

Since the app does not need to be on the PlayStore and I don't need the latest API version, I was hoping there would be an easier way for me to store the data even if the app is reinstalled.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Since the app does not need to be on the PlayStore and I don't need the latest API version, I was hoping there would be an easier way for me to store the data even if the app is reinstalled.
Use a target SDK of 28 and use the runtimepermission library.
B4X:
Sub Activity_Create(FirstTime As Boolean)    
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)  '
    Wait For Activity_PermissionResult (Permission As String, PResult As Boolean)
    If PResult = False Then
        MsgboxAsync("No permission to access external storage", "")
        Return
    Else
        If Starter.SQL1.IsInitialized =False Then        
            Starter.SQL1.Initialize(Starter.DBFilePath,Starter.DBFileName,True)
        End If
    End If
Note that rp, DBFilePath , DBFileName were declared in starter service. IThey do not have to be.in starter.
for example: DBFilePath = File.DirRootExternal or a subfolder of File.DirRootExternal
 
Upvote 0
Top