following observeForever not giving any data when - User is logged out (There is no user in the database) - Login and insert a user into the db. (Here observeForever is not being triggered)
mUserDao.getCompleteUser().observeForever(this::updateCompleteUser);
DAO
@Dao
public interface UserDao extends BaseDao<User> {
@Query("SELECT * FROM user")
@Transaction
LiveData<CompleteUser> getCompleteUser();
}
But @Query("SELECT * FROM user") @Transaction Flowable<CompleteUser> getCompleteUser();
is working which does not return null for the logged-out state (expected behavior)
User
@Entity(tableName = "user")
public class User implements Serializable {
@PrimaryKey
@NonNull
String uid;
String email;
}
Complete User
public class CompleteUser {
@Embedded
User user;
@Relation(parentColumn = "uid", entityColumn = "userId", entity = Address.class)
List<Address> addresses;
}
为了得到一个User
与List<Address>
,你可以看看这个看看在处理这样的关系。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.