我正在使用NavController来启动一个活动 - 它有自己的导航图 - 用于登录/注册流程。
现在我想在更新 UI时获得LoginActivity(成功、失败)的结果。MainActiviy
MainActvity (start)-> LoginActivity
MainActvity <-(result) LoginActivity end
Run Code Online (Sandbox Code Playgroud)
是否可以使用导航组件来处理这种情况,或者我是否必须使用类似的东西startActivityForResult(LoginActivity...)来获取结果LoginActivity?
或者,还有更好的方法?我认为一个可能的解决方案可能是在 Activity 之间使用相同的 viewModel 实例,但不确定这是否可行。:-/
android android-activity onactivityresult android-architecture-navigation
I'm trying to handle a LiveData value (profilePicture: Bitmap) within a BindingAdapter function but the first value is always null. The binding adapter is a ViewSwitcher with ProgressBar and ImageView.
Getting profile picture from firebase like this:
val downloadPictureResult = MutableLiveData<Bitmap>()
// ...
fun downloadProfilePic(): LiveData<Bitmap?> {
val imageRef = storage.getReference("images/$uid/profile/profile_picture.jpg")
imageRef.getBytes(ONE_MEGABYTE).addOnCompleteListener { task ->
if (task.isSuccessful) {
//...
downloadPictureResult.value = responseBitmap
//...
} else {
downloadPictureResult.value = null
Log.d(TAG, task.exception?.localizedMessage)
}
}
return downloadPictureResult;
} …Run Code Online (Sandbox Code Playgroud)