I've been trying to find a way to notify currently active observers if data in Room database has changed. All my data is wrapped in LiveData observer objects and then they have an observer attached to them.
This is one of the basic Daos.
@Dao
public interface SubcategoryDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertSubcategory(Subcategory... subcategories);
@Query("SELECT * FROM subcategory_table")
LiveData<List<Subcategory>> getAllSubcategories();
@Query("SELECT * FROM subcategory_table WHERE category_id=:catId")
LiveData<List<Subcategory>> getAllSubcategoriesForCategory(int catId);
@Query("SELECT id FROM subcategory_table WHERE title=:title")
LiveData<Integer> getSubcategoryIdByTitle(String title);
@Query("SELECT * FROM subcategory_table WHERE title=:title")
LiveData<Subcategory> getSubcategoryByTitle(String title);
}
I am receiving SQL string queries from server and then the only way to execute them according to documentation is this:
AppDatabase.getInstance(activity)
.getOpenHelper()
.getWritableDatabase()
.execSQL(sqlQuery);
So how do I make it work with observers? How do I notify or invalide them to reload ui?