当 updating/deleting 来自 room dao 时触发自定义事件

Trigger custom event when updating/deleting from room dao

我想知道是否可以在调用房间 dao 上的方法时触发自定义事件。在我的特定情况下,我想在删除引用该文件的实体后删除该文件。我有一个名为 Picture 的实体,它包含磁盘上实际文件的路径。当 Picture 的实体从数据库中删除时,如果它是由应用程序保存在应用程序目录中,我也需要删除该文件。经过相当多的研究,我找不到适合我需要的任何东西。提前致谢

i would like to know if it is possible to trigger a custom event when a method on a room dao is called

不,抱歉。

When an entity of Picture is deleted from the database i need to remove the file as well if it was saved by the app / in the app directory

无论您调用 DAO 上的 @Delete 方法的什么代码,都负责删除文件。

在 room 中,如果没有删除任何项目或 return 删除的总行数,则在您的 dao 中使用 @Delete 注释进行注释的任何方法都将 return "int" 0。

你可以这样做。

if(yourDB.getYourDao.delete()>0){

    //Do task you want to perform on deletion.
}