As the title say. I have search for a solution but I thing i'm on the wrong path with this.
I feels like the easiest way would be to setup a new db when the app recognizes user change. Max 2-3 users. The flow of the ContentProvider
will be the same for all users. Well yes I could tag all insert's with some user-id but that sounds to easy :) I can drop the ContentProvider
if`necessary to make this work.
Any idea about a good approach to this?
After some research I see that ContentProvider
is loaded before the Application so it's difficult to change the db name. Also SQLiteOpenHelper
onUpgrade()
need to upgrade many database files in this case. Is the Manifest registered ContentProvider
db name written in stone?
Here's part of the Table layout, I have more, like 10 tables
public final class TableUser {
public TableUser() {
}
public static final class User implements BaseColumns {
private User() {
}
public static final Uri CONTENT_URI = Uri.parse("content://" + UserContentProvider.AUTHORITY + "/user");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.doktor.user";
public static final String USER_ID = "_id";
public static final String UUID = "uuid";
public static final String USERNAME = "username";
public static final String USERPASSWORD = "userpassword";
public static final String REGISTRATIONID = "registrationid";
public static final String LAST_LOGGED_IN = "lastloggedin";
}
public static final class FriendRequests implements BaseColumns {
private FriendRequests() {
}
public static final Uri CONTENT_URI = Uri.parse("content://" + UserContentProvider.AUTHORITY + "/friendRequests");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.doktor.friendRequests";
public static final String FRIENDREQUESTS_ID = "_id";
public static final String NAME = "name";
public static final String UUID = "uuid";
public static final String MESSAGE = "message";
public static final String NOTIFICATION_ID = "notification_id";
public static final String DEVICE_TYPE = "device_type";
public static final String ADDEDDATE = "added_date";
}
}
Here is the table creation
db.execSQL("CREATE TABLE " + USER_TABLE_NAME + " (" +
User.USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
User.UUID + " VARCHAR(255)," +
User.USERNAME + " VARCHAR(255)," +
User.USERPASSWORD + " VARCHAR(255)," +
User.REGISTRATIONID + " LONGTEXT," +
User.LAST_LOGGED_IN + " VARCHAR(255)" + ");");
db.execSQL("CREATE TABLE " + FRIEND_REQUEST_TABLE_NAME + " (" +
FriendRequests.FRIENDREQUESTS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
FriendRequests.NAME + " VARCHAR(255)," +
FriendRequests.UUID + " VARCHAR(255)," +
FriendRequests.MESSAGE + " VARCHAR(255)," +
FriendRequests.NOTIFICATION_ID + " VARCHAR(255)," +
FriendRequests.DEVICE_TYPE + " VARCHAR(255)," +
FriendRequests.ADDEDDATE + " VARCHAR(255)" + ");");