0

I am learning about databases in android and I realized that in android it's not like that you create your database and put it somewhere in memory and get access to it, rather you create and put data within the app. I learned a way to create my SQlite DB outside the code and copy it to assets folder and use InputStream to copy it to newly created DB that you can find this code from HERE

So my question is that is't this kind of data redundancy because my already created DB packs inside .apk file and meanwhile when app runs for first time I create another DB and copy my Data to newly created DB?

I know there are another ways to do this, for example create a XML file or even use INSERT operation to put data to database but aren't all these ways kind of extra works?

1 Answer 1

2

So my question is that is't this kind of data redundancy because my already created DB packs inside .apk file and meanwhile when app runs for first time I create another DB and copy my Data to newly created DB?

You will have two copies of the data, one in the asset and one on internal storage. The asset copy should be compressed in the ZIP archive, which helps a bit.

BTW, I hope that you are using SQLiteAssetHelper for this.

I know there are another ways to do this, for example create a XML file or even use INSERT operation to put data to database but aren't all these ways kind of extra works?

Yes.

The only way to avoid the redundant copy would be to download the database from the Internet when your app first runs. However, this then requires Internet access, which may or may not be convenient for the user right then.

3
  • How can I use SQLiteAssetHelper? I added the line at app/gradle.build but I can't import com.readystatesoftware.sqliteasset.SQLiteAssetHelper
    – Morteza
    Apr 8, 2015 at 23:04
  • @Morteza: Something must be wrong with your build.gradle files. In addition to the sample app on the library's repo, here is another sample app, this one definitely set up for use with Android Studio and Gradle for Android. Apr 8, 2015 at 23:09
  • It seems that I had internet proxy settings that prevented AS from downloading the library solved my problem by refreshing proxy settings.
    – Morteza
    Apr 8, 2015 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.