/ / Jak osiągnąć synchronizację w pokoju (biblioteka trwałości Androida) - Android, Android-room

Jak osiągnąć synchronizację w pokoju (biblioteka trwałości Androida) - Android, sala Android

W normalnym sqlite możemy łatwo osiągnąć synchronizację, ale jak ją wdrożyć w pokoju

Odpowiedzi:

0 dla odpowiedzi № 1

Tutaj jest próba który pokazuje, jak korzystać z pokoju z dostawcą treści, który następnie można połączyć (ContentProvider) z SynchronizationAdapter.

Powiedziawszy, że możesz zmodyfikować swój model pokoju w podobny sposób

    @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;
}
}

0 dla odpowiedzi nr 2

Jak powiedziałeś „synchronizacja z SQLITE jest łatwa”

Pokój korzysta wewnętrznie z bazy danych SQLite. Wierzę, że metody SQLite są dostępne w pokoju. W związku z tym powinno być łatwo również z miejscem.

To powiedziało, że klasy Sqlite są opakowane w klasy Room, być może będziesz musiał napisać trochę hydrauliki. Czego używasz do łatwej synchronizacji?