Fixed crash if sharedViewModel has not been initialized when saving fragment instance state
This commit is contained in:
parent
60cc5a31c4
commit
72ae8f2e67
1 changed files with 9 additions and 5 deletions
|
@ -109,11 +109,15 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
val chatRoom = sharedViewModel.selectedChatRoom.value
|
||||
if (chatRoom != null) {
|
||||
outState.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly())
|
||||
outState.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly())
|
||||
Log.i("[Chat Room] Saving current chat room local & remote addresses in save instance state")
|
||||
if (::sharedViewModel.isInitialized) {
|
||||
val chatRoom = sharedViewModel.selectedChatRoom.value
|
||||
if (chatRoom != null) {
|
||||
outState.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly())
|
||||
outState.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly())
|
||||
Log.i("[Chat Room] Saving current chat room local & remote addresses in save instance state")
|
||||
}
|
||||
} else {
|
||||
Log.w("[Chat Room] Can't save instance state, sharedViewModel hasn't been initialized yet")
|
||||
}
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue