1

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?

KarlCobb
  • 149
  • 1
  • 9

1 Answers1

2

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.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • "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." This should be considered as best practice. – Amit K. Saha Mar 12 '16 at 06:22
  • I agree, but it takes the most time. I consider 1 acceptable in most cases (reasonable amounts of data need re downloading) – Gabe Sechan Mar 12 '16 at 06:24
  • I am not disagreeing with you regarding the downloading concept. But OP asked about locally stored data, isn't it? – Amit K. Saha Mar 12 '16 at 06:24
  • Number 3 does make sense, although I wish it were possible just to tag a table with a username. Can you confirm that there is no way to make another SQlite table on the fly with the username tagged to the table name? And Amit, that's right. I don't want to store chat messages on the server. – KarlCobb Mar 12 '16 at 06:42
  • You can. You can create a table at any time. Its not something that scales to a large number of users, but its probably doable for a small number like you'd get on one device. – Gabe Sechan Mar 12 '16 at 06:43
  • This is obviously deviating from the original question, so I'll open another question if this goes on for a while. Do you have a link to a method to create another table along side previous tables? It seems like every time a table is created the database has to be updated which deletes everything. – KarlCobb Mar 12 '16 at 06:52
  • Just send a CREATE TABLE sql command to the database via rawQuery. The whole onCreate and version thing is a convenience. Although this will make upgrades harder- if you have 3 XXXusername tables, you have to upgrade all 3. – Gabe Sechan Mar 12 '16 at 06:54
  • Ok that all seems to make sense. Thanks! – KarlCobb Mar 12 '16 at 07:06
  • try to utilize the the public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) in yourr SQLiteOpenHelper @KarlCobb. – Amit K. Saha Mar 12 '16 at 07:37