Search code examples
androidsqlitemultiple-users

Best practice for saving multiple users' data locally on device (Or is it necassary?)


My app has a chat feature, and the chats are held in SQLite. Currently this is an issue if multiple users use the same phone. Chats from all the users would show up in the past message areas, although the messages would appear to be sent from the person who is presently logged into the app. My question then is: How do apps generally deal with this issue? Or do they assume most people will login to the app from their own device or create another user account on the device itself -- therefore leaving the problem to the device user since it is not a normal problem?


Solution

  • So Android does have user accounts, but nobody really uses them. Multi-account isn't a big issue for phones, but its a bigger one for tablets which tend to be shared more among a family. (Sharing phones also isn't totally uncommon in some parts of the world). There's really nothing you can do if a logged in user sees incoming messages, but you should provide logout button.

    There's three main methods of dealing with multiple accounts:

    1)When a user logs out, delete all local data specific to the user. Redownload it from the web when they log back in. 2)Ignore it. It's unprofessional but a lot of people take this shortcut. 3)Make sure all data is tagged with a user id, and only allow the matching user id's data to appear in the app.