连续添加类型转换器实时数据触发器后
这是我的 JobImages 实体
@Entity
@TypeConverters({AddOnConverter.class})
public class JobImagesTable {
@PrimaryKey(autoGenerate = true)
int id;
@ColumnInfo(name = "job_marked_image")
String jobMarkedImage;
@ColumnInfo(name = "complexity_id")
int complexityId;
@ColumnInfo(name = "addons_data")
ArrayList<AddonService> addOnsData = new ArrayList<>();
@ColumnInfo(name = "status")
int status;
}
这是我的 DAO
@Dao
public interface JobImagesDao {
@Query("SELECT * FROM JobImagesTable WHERE job_id=:job_id AND is_delete = 0")
LiveData<List<JobImagesTable>> getImagesForView(int job_id);
}
AddOnService 类
public class AddonService implements Parcelable {
@SerializedName("AddonID")
@Expose
private int addonID;
@SerializedName("Name")
@Expose
private String name;
@SerializedName("ExtraCredits")
@Expose
private double extraCredits;
@SerializedName("isSelected")
@Expose
private boolean isSelected;
public AddonService() {
}
}
转换器类
public class AddOnConverter {
@TypeConverter
public static ArrayList<AddonService> fromString(String value) {
Type listType = new TypeToken<ArrayList<AddonService>>() {}.getType();
return new Gson().fromJson(value, listType);
}
@TypeConverter
public static String fromArrayList(ArrayList<AddonService> list) {
Gson gson = new Gson();
String json = gson.toJson(list);
return json;
}
}
这个数据库类
@Database(entities = {JobImagesTable.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
public abstract JobImagesDao getOriginImagesDao();
}
我没有收到任何编译时错误,但是在添加类型转换器后进入屏幕时 Livedata 连续触发有什么问题吗?