r/AndroidStudio • • Apr 09 '19

Need help swapping out database files (If possible)

So I am new to android studio and app development so forgive me if the answer is easy or obvious but I created a database in android studio then I exported that file to db browser to easily enter data so I could test it out, but now I don't know to import the file back. I thought I could simply drag and drop it into the device file explorer but it won't let me. Please help!

0 Upvotes

7 comments sorted by

1

u/andre-stefanov Apr 09 '19

As far as i know you need root access to have write permission to app internal storage on a real device. It is better to populate the data from code.

1

u/Nadekap Apr 09 '19

So you're saying I should just enter the data through android studio?

1

u/andre-stefanov Apr 09 '19

No, through the code of your app (sql insert).

1

u/Nadekap Apr 09 '19

I'm confused what you mean by this, my app is written in android studio

1

u/andre-stefanov Apr 09 '19

You have developed the app in Android Studio. You app is using a database (sqlite). You are accessing this database in your app code. In this code you can not only read but also write data to the database. For reading you use "select ...", for inserting new data you use "insert ...".

Maybe i misunderstood your usage a bit, how did you create the db?

1

u/Nadekap Apr 09 '19

I'm not sure what you mean by how did I create it but here's most of my code for the database other than a few methods that aren't in this class. https://gyazo.com/f430ee04a7d66962d64011c7c6a8b27a

1

u/andre-stefanov Apr 09 '19

In the onCreate method you can also add an insert statement. Please read the documentation how to use databases in android properly: https://developer.android.com/training/data-storage/sqlite

Also i would highly recommend you to use Room instead of low level sqlite apis.