正如标题所说。我正在寻找解决方案,但我认为我走错了路。我觉得最简单的方法是在应用程序识别出用户更改时设置一个新的数据库。最多 2-3 个用户。所有用户的流程都是ContentProvider
相同的。好吧,是的,我可以用一些用户 ID 标记所有插入,但这听起来很容易 :) 我可以放弃ContentProvider
if`necessary 来完成这项工作。关于解决这个问题的好方法有什么想法吗?
经过一些研究,我发现它ContentProvider
是在应用程序之前加载的,因此很难更改数据库名称。这种情况下还 SQLiteOpenHelper
onUpgrade()
需要升级很多数据库文件。清单注册的ContentProvider
数据库名称是用石头写的吗?
这是表格布局的一部分,我还有更多,比如 10 个表格
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";
}
}
这是表创建
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)" + ");");