Android的房间不返回任何与网址作为参数

我试图通过Feed的主键来访问项目列表,如下所示。 主键是一个url。 试图像这样访问它给了我空回来,并指出把:arg0在引号中创建一个编译时错误error: Unused parameter: arg0 。 是否有可能使用此查询的网址?

 @Query("SELECT * FROM item WHERE feed_url = :arg0") fun observeAllByFeed(feedUrl: String): LiveData<List<Item>> 

项目

 @Entity(foreignKeys = arrayOf(ForeignKey( entity = Feed::class, parentColumns = arrayOf("url"), childColumns = arrayOf("feed_url")))) data class Item( @ColumnInfo(name = "guid") @PrimaryKey var guid: String = "", @ColumnInfo(name = "categoryIds") var categoryIds: List<Int> = emptyList(), @ColumnInfo(name = "comments") var comments: String? = null, @ColumnInfo(name = "content") var content: String? = null, @ColumnInfo(name = "description") var description: String = "", @ColumnInfo(name = "author") var author: String = "", @ColumnInfo(name = "block") var block: Boolean = false, @ColumnInfo(name = "duration") var duration: Int = 0, @ColumnInfo(name = "explicit") var explicit: String = "", @ColumnInfo(name = "image_url") var imageUrl: String = "", @ColumnInfo(name = "keywords") var keywords: List<String> = emptyList(), @ColumnInfo(name = "subtitle") var subTitle: String = "", @ColumnInfo(name = "summary") var summary: String = "", @ColumnInfo(name = "link") var link: String = "", @ColumnInfo(name = "publication_date") var pubDate: Date = Date(), @ColumnInfo(name = "title") var title: String = "", @ColumnInfo(name = "feed_url") var feedURL: String = "", @ColumnInfo(name = "download_state") var downloadState: Int = Item.DownloadState.STATE_NOT_DOWNLOADED ) : Serializable { companion object DownloadState { val STATE_NOT_DOWNLOADED = 0 val STATE_DOWNLOADING = 1 val STATE_DOWNLOADED = 2 } } 

饲料

 @Entity(foreignKeys = arrayOf(ForeignKey( entity = Owner::class, parentColumns = arrayOf("id"), childColumns = arrayOf("owner_id") ))) data class Feed( @ColumnInfo(name = "url") @PrimaryKey var URL: String = "", @ColumnInfo(name = "copyright") var copyright: String? = null, @ColumnInfo(name = "description") var description: String? = null, @ColumnInfo(name = "itemGUIDs") var itemGUIDs: List<String> = emptyList(), @ColumnInfo(name = "author") var author: String? = null, @ColumnInfo(name = "block") var block: Boolean = false, @ColumnInfo(name = "categoryIds") var categoryIds: List<Int> = emptyList(), @ColumnInfo(name = "explicit") var explicit: Boolean = false, @ColumnInfo(name = "image_url") var imageUrl: String? = null, @ColumnInfo(name = "owner_id") var ownerId: Int = -1, @ColumnInfo(name = "subtitle") var subtitle: String? = null, @ColumnInfo(name = "summary") var summary: String? = null, @ColumnInfo(name = "language") var language: String = "", @ColumnInfo(name = "link") var link: String = "", @ColumnInfo(name = "title") var title: String = "", @ColumnInfo(name = "expiry") var expiry: Date = Date(), @ColumnInfo(name = "subscribed") var subscribed: Boolean = false ) : Serializable 

所有者

 @Entity data class Owner( @ColumnInfo(name = "name") var name: String? = null, @ColumnInfo(name = "email") var email: String? = null ) : Serializable { @ColumnInfo(name = "id") @PrimaryKey(autoGenerate = true) var id: Int = 0 } 

事实证明,当与房间一起使用LiveData时,它立即返回,所以调用LiveData.value立即给出null而它异步获取实际的数据提供给观察员,所以不能被用作替换的下降,如果试图转换从一个非LiveData调用。 这是记录在这里: https : //developer.android.com/reference/android/arch/lifecycle/LiveData.html#getValue()

返回当前值。 请注意,在后台线程上调用此方法并不能保证会收到最新的值集。