androiddatabasesqliteandroid-studiodata-sharing

Sqlite database with android - local?


I have an android app that I have been working on and I created a sqlite database using the android.database.sqlite package. I know that you can access that data by using Android Studio manually, but I am trying to save data into the database so that if one user of the app does something to add to the database, another user of the app will have the same access to the database. Will the android.database.sqlite package allow this or will the database for each user be unique to that user? If this is the case in which all users cannot access the same database after updating, what is the best way to go about creating a database that would let every user access it even when updates occur?


Solution

  • It is possible to add multiple users to a local application. Here is the simplest way to accomplish this:

    1) Create a table for users in your database, with a user ID
    2) Every user specific value in other tables should be marked to corresponding users with this ID
    3) When you fetch the data from database, use the Select statement specifying user

    Tip: Android has an Object-Relational-Mapping Library called Room for making database creation simpler. Reading about Room would help too! Take database classes for gaining knowledge about such common tasks.