LiveData.getValue() returns null with Room

前端 未结 7 849
无人及你
无人及你 2020-12-05 13:16

Java POJO Object

public class Section {

    @ColumnInfo(name=\"section_id\")
    public int mSectionId;

    @ColumnInfo(name=\"section_name\")
    public S         


        
相关标签:
7条回答
  • 2020-12-05 14:17

    I resolved the similar issue as follows

    Inside your ViewModel class

    private LiveData<List<Section>> mSections;
    
    @Override
    public LiveData<List<Section>> getAllSections() {
    
        if (mSections == null) {
            mSections = mDb.sectionDAO().getAllSections();
        }
    
        return mSections;
    }
    

    This is all required. Never change the LiveData's instance.

    0 讨论(0)
提交回复
热议问题