I am just a beginner in android programming. Recently I am reading about how room database can return live data for automatic updates when changes were made to the database. I am using the viewmodel class instance to hold my Livedata as follows
public class LogVM extends AndroidViewModel{
MasterDatabase roomDatabase;
LiveData<List<Log>> logData;
LogVM(Application application){
super(application);
roomDatabase=MasterDatabase.getInstance(application);
logData=roomDatabase.getLogDao.getAllLogs();
}
public LiveData<List<Log>> getLogData() {
return logData;
}
}
The above code actually works fine. But my question is when initializing the logdata in the constructor, aren't we running the database operation on the main thread? But the code compiles and runs without any warning. Can someone explain how?? Sorry if its a silly question. But I am just a beginner!