Commit 039e3c35 authored by Lucio Maciel's avatar Lucio Maciel

Check if the fragment is still active before accessing views

parent 7ddd9215
...@@ -62,6 +62,11 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -62,6 +62,11 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
presenter.loadChatRooms() presenter.loadChatRooms()
} }
override fun onDestroyView() {
listJob?.cancel()
super.onDestroyView()
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater) super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.chatrooms, menu) inflater.inflate(R.menu.chatrooms, menu)
...@@ -80,7 +85,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -80,7 +85,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
} }
override suspend fun updateChatRooms(newDataSet: List<ChatRoom>) { override suspend fun updateChatRooms(newDataSet: List<ChatRoom>) {
activity.apply { activity?.apply {
listJob?.cancel() listJob?.cancel()
listJob = launch(UI) { listJob = launch(UI) {
val adapter = recycler_view.adapter as ChatRoomsAdapter val adapter = recycler_view.adapter as ChatRoomsAdapter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment