viewmodel中有这么一个变量: val pb:MutableLiveData<Int> = MutableLiveData() 在fragment中赋值的时候,要用setValue,不能用postValue,不然没效果
因为我在主线程上更新,文档中有这么一段话:
注意:您必须调用 setValue(T) 方法以从主线程更新 LiveData 对象。如果在工作器线程中执行代码,您可以改用 postValue(T) 方法来更新 LiveData 对象。
使用数据绑定binding,一定要记得设置binding的lifecycleowner!!!!不设置的话,如果和视图绑定的viewmodel里的字段是livedata, 然后在fragment中postValue(new_value)
既然都绑定了,那么肯定希望视图上的数据也变化,可是如果不设置lifecycleowner的话,视图是不会变化的
在gradle.properties 文件中添加如下指令: android.injected.testOnly=false
If you use the CameraX
API, be sure that backpressure strategy is set to its default value ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
.
This guarantees only one image will be delivered for analysis at a time.
If more images are produced when the analyzer is busy, they will be dropped automatically and not queued for delivery.
Once the image being analyzed is closed by calling ImageProxy.close(), the next latest image will be delivered.
这段话的意思就是说,如果mlkit和camerax配合使用的话,camerax的imageAnalyzer模式要使用ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
.
还有,对于imageProxy,分析完要记得调用close,具体参考https://github.com/googlesamples/mlkit/blob/e949654bef09e97b237c7692349c52ee06e9fd9e/android/vision-quickstart/app/src/main/java/com/google/mlkit/vision/demo/java/VisionProcessorBase.java#L178-L181
原文:https://www.cnblogs.com/--here--gold--you--want/p/14881836.html