I'm creating an app which allows a user to login and retrieve some information about his account from a server. These information are inserted in a SQLite database, and then the user can set other preferences on them (I use sharedpreferences for this).
Now i want to expand the app allowing more users to login.
The problem is that i don't know exactly how to manage the database with multiple users, infact:
if I keep db after logout, and login with another account, I find the information related to the previous user;
if I don't keep the db, and erase it after logout, I miss all the preferences set by the user;
How can I solve this problem? Thanks..
This can be done in multiple ways
1. Have user id table created and link that to other tables using foreign key.
another way is
2. create new DB for each of the users. so your database name will have username. If user name changes then database changes.
with second way your code changes will be minimal.
Related
I am currently working on a android application, where I want to save the login details. I am using a unique id (primary key auto increment in mysql table) to uniquely retrieve the details from the table. I am using this id has a login attribute. How to make it as auto login or, when the user enters the login page, the id should be already present?
You can use SQLITE DB for this. When user login than data will be save in SQLITE DB. Sorry I couldn't comment. I have low reputation..
It's not a code problem but it's just by my curiosity.
I am making an application that can be logged in by social login, and also email login.
In my application, I plan to use some SQLiteDatabase to save simple datas.
However, when I just save it with A account and login with different account, won't there be conflict because its the same device and server is not intervened with it? How do you know it's different account when its the same device, one application?
Think its sort of a silly question maybe, but if there's a way that everyone uses to solve it, I would like to know.
There can be two cases -
You want to use same database for different users -
In this case, there is no problem as your SQLite database gets saved in your app's /data/data folder which will be always accessible from inside your app.
You want to use different database for different users -
In this case, you have to add user_id column in all the tables of your SQLite database, and based on your user_ids, you can do your database actions like query, deletion, etc
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?
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.
Currently I have developed an android application that uses a local sqlite database per installation. The database comes pre-populated with static tables, and the entire point of the application is to allow the user to assign dates/comments with the pre-populated information in each table.
I am looking to bring this online, and move the database to a mysql format, allowing access via desktops and other mobile devices. Is the best way to handle this to assign each new user a new database?
I would strongly avoid creating multiple databases, and instead add relationships to the existing database structure you have with a users table. Each user has an association to each existing object. Keep in mind sharing with other users in the event that you may want to allow one user to see another user's info.
My suggestion is provide an update to the app where after the first launch after updating it pushes their information to your MySQL database and inform the users that they can access their data via other methods now.
how many user to you expect? I would use only one database with a user table instead of hundreds/thousands of databases.
One table for all users (only with user info like id, email, password, etc).
Another table with comments (with user id and his comment), so that you can add as many comments per user as needed. If dates are related to comments put them on this table, else another table for dates as well.
I am thinking about the design of an android application which will need to create user accounts and have some information about the app users. While researching in the internet and the developer site, I got the impression that to maintain the database , you have to have a server.
What if I don't want to maintain the account information in my own server (i.e. I am not willing to maintain my own server for this), what options do I have and what will be their drawbacks (if any).
If there is no other choice but to use a server, then can I get suggestions as to how can I modify my design so that I don't have to use a server.
I am a novice at this field, so I would appreciate advice.
Thanks in advance!
Create external database file with credential table in this table create appropriate columns like username,password etc..here if you have registered users then store those users details in credential table.Finally copy that database in assests folder then using SqliteOpenHelper class copy that external database to phone memory.Here you need to maintain registration page with conditions.If the user completes the registrations procedure with your conditions then store his/her details in credential table.When user wants to login to the App please check the username and password in credential table.