I have a DAO as follows.
@Dao
public interface PostDAO {
@Query("SELECT * FROM posts order by time DESC")
LiveData<List<Post>> getPosts();
@Insert(onConflict = OnConflictStrategy.REPLACE)
@NonNull
void insert(Post... posts);
@Delete
void delete(Post post);
@Query("SELECT * FROM posts WHERE id = :id")
Post getPost(String id);
@Query("SELECT * FROM posts WHERE id = :id")
LiveData<Post> getPostLiveData(String id);
}
I understand that I can listen for new added data with something like the following.
postDAO().getPosts().observe(builder.getLifecycleOwner(), data::postValue)
But how can I know when a post has been deleted?