Search code examples
androidsqliteandroid-sqlite

Does SQLite Store Data from all Phones in a Single Database or does each Android Phone Read from a Different DB?


I'm a little confused as to how SQLite works in Android development. I know it can be used to store data but is this internal data only? It will write to a .db file on the phone which is just a test file. But say I insert a few records on my phone. When a different user logs in and views the database will they see the records I just inserted or are those records only going to display on my phone? If it's the latter what's the best way to have all the data be stored in a single database so all users can add / delete from the same pool of records? Would it be a web service callout to a cloud db like MySQL?


Solution

  • I know it can be used to store data but is this internal data only?

    Yes, if I understand what you mean by "internal data".

    When a different user logs in and views the database will they see the records I just inserted or are those records only going to display on my phone?

    Well, that depends entirely on what you mean by "logs in".

    If you mean "a different user uses my phone, just by swiping to unlock", the phone cannot tell you apart from this other person, and therefore that user sees the same data that you do.

    If you mean "a different user uses my phone, but I set up two user accounts on the phone, and that user has logged into my guest account", then that user will get a separate database (and separate everything: apps, etc.).

    If you mean "a different user uses their phone, but uses the same app", then that user will get a separate database, because it is a separate device. This is not significantly different than the user having different word processing files on their computer compared to your computer.

    From the standpoint of the Android SDK, the SQLite database is a file on the device.

    If it's the latter what's the best way to have all the data be stored in a single database so all users can add / delete from the same pool of records? Would it be a web service callout to a cloud db like MySQL?

    I would not consider MySQL to be a "cloud db", but, yes, your app could communicate with a Web service that stores its data in its own central database.