LiveData更新数据时报错:
java.lang.IllegalStateException: Cannot invoke setValue on a background thread
报错原因:
在非主线程中对LiveData数据进行setValue更新数据,setValue(T) 必须在主线程中调用 , 不能在非主线程中调用,如果要在非主线程中调用,要使用postValue(T)接口,它可以在主线程中调用, 也可以在子线程中调用。
解决办法:
将setValue改成postValue
参考文档:
https://blog.csdn.net/xingxtao/article/details/89424110