在普通的sqlite中,我们可以轻松实现同步,但是如何在 session 室中实现同步

最佳答案

这是sample,它显示如何将Room与Content Provider一起使用,然后可以将(ContentProvider)与SynchronizationAdapter链接。

话虽如此,您可以像修改房间模型一样

@Entity(tableName = Student.TABLE_NAME)
public class Student {
    /** The name of the Student table. */
    public static final String TABLE_NAME = "student";


    /** The name of the ID column. */
    public static final String COLUMN_ID = BaseColumns._ID;


    /** The name of the name column. */
    public static final String COLUMN_NAME = "name";


    /** The unique ID of the Student*/
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(index = true, name = COLUMN_ID)
    public long id;


    /** The name of the Student*/
    @ColumnInfo(name = COLUMN_NAME)
    public String name;


    /**
     * Create a new {@link Studentfrom the specified {@link ContentValues}.
     *
     * @param values A {@link ContentValues} that at least contain {@link #COLUMN_NAME}.
     * @return A newly created {@link Student} instance.
     */
    public static Student fromContentValues(ContentValues values) {
        final Student student= new Student();
        if (values.containsKey(COLUMN_ID)) {
            student.id = values.getAsLong(COLUMN_ID);
        }
        if (values.containsKey(COLUMN_NAME)) {
            student.name = values.getAsString(COLUMN_NAME);
        }
        return student;
    }
}

关于android - 如何在 session 室中实现同步(Android持久性库),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44878623/

10-10 16:05