假设在apk中我们在strings.xml中有1000个字符串.
因此,当我们在设备上运行此应用程序时,所有字符串始终在堆内存中可用.或者当我们调用getString()
Context的方法来加载字符串时,它们会加载到内存中.
运行时是否所有字符串都在堆中?
即使AsyncTask在internalHandler中使用Looper.getMainLooper(),为什么也必须按文档中所述在UI线程上调用AsyncTask
的方法?execute(Params...)
我尝试创建任务并从后台线程调用其execute(Params ...),它工作正常。
使用Retrofit,我可以获取用户列表,但是如果出现错误,我应该如何管理向UI发送通知。
我在MVVM模式中使用Android体系结构组件“ ViewModel”,“ LiveData”,并将Retrofit用作网络库。
我已经在springBoot应用程序中添加了H2DB以进行单元测试。
我在application-test.properties中添加了:
spring.datasource.name = h2db
spring.h2.console.enabled = true
它的工作正常,保存值。
但是它是如何工作的以及如何浏览该数据库?
我的代码
fun weatherByCity(cityName: String): LiveData<Resource<Response>> = liveData(Dispatchers.IO) {
val response = appRepository.weatherByCity(cityName)
emit(response)
}
fun weatherByZipCode(zipCode: String): LiveData<Resource<Response>> = liveData(Dispatchers.IO) {
val response = appRepository.weatherByZipCode(zipCode)
emit(response)
}
fun weatherByLocation(latLong: String): LiveData<Resource<Response>> = liveData(Dispatchers.IO) {
val response = appRepository.weatherByLocation(lat?:"", long?:"")
emit(response)
}
Run Code Online (Sandbox Code Playgroud)
在这里,我使用了三个 liveData{} 块,它们从存储库中获取数据并进行改造。但它们具有相同的返回类型LiveData<Resource<Response>>
。我可以对所有三个都使用单个 liveData{},如果是,那么该怎么做?还有一个问题,使用 liveData(Dispatchers.IO) 还是使用 liveData{}(不使用 Dispatchers.IO)会有什么不同?
android kotlin android-livedata mutablelivedata kotlin-coroutines