Android Question including files into project for development

leitor79

Active Member
Licensed User
Longtime User
Hi,

I need to use a sqlite file on my app, and I'm not sure about the implementation since I've never used a database on an android app before.

Would you recommend to create it within the app, if the file doesn't exist, or It's better to create it with some tool (sqlite database explorer), adding it into the files's project and be copied to the device upon development?

If the last case is recommended; adding the file into the files's project will automatically make the file to be copied into the device? Where (file.dirrootinternal, etc?)? I need the file to be read/write, and not to be automatically deleted when the devices runs low on storage...

Thank you very much!
 

Eumel

Active Member
Licensed User
Longtime User
You can make both. Create with code, or put in in the files folder.

The second way, you must copy the db from "file.dirAssets" to the folder you need at Appstart.

B4X:
    If File.Exists(DBFileDir,DBFileName) = False Then
        File.Copy(File.DirAssets,DBFileName,DBFileDir,DBFileName)
    End If

If your device has a sd card, you can copy it there. So test it with

B4X:
    If File.ExternalWritable = True Then
        DBFileDir = File.DirDefaultExternal
   Else
        DBFileDir = File.DirInternal
   End If


-----------------
Eumel
 
Upvote 0
Top