fix: Catch and swallow snackbar exception (#536)
For reasons not fully understood the root of a fragment's view might not have relevant view from the activity set as its parent. This causes `Snackbar.make()` to throw an exception, and crash. See https://issuetracker.google.com/issues/228215869. For now, "fix" this by swallowing the exception. Not showing the error is better than crashing.
This commit is contained in:
parent
bdbe2f85c2
commit
9535506596
|
@ -127,9 +127,16 @@ abstract class SFragment<T : IStatusViewData> : Fragment(), StatusActionListener
|
||||||
it.msg(requireContext()),
|
it.msg(requireContext()),
|
||||||
)
|
)
|
||||||
Timber.e(msg)
|
Timber.e(msg)
|
||||||
|
try {
|
||||||
Snackbar.make(requireView(), msg, Snackbar.LENGTH_INDEFINITE)
|
Snackbar.make(requireView(), msg, Snackbar.LENGTH_INDEFINITE)
|
||||||
.setAction(R.string.action_retry) { serverRepository.retry() }
|
.setAction(R.string.action_retry) { serverRepository.retry() }
|
||||||
.show()
|
.show()
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
// On rare occasions this code is running before the fragment's
|
||||||
|
// view is connected to the parent. This causes Snackbar.make()
|
||||||
|
// to crash. See https://issuetracker.google.com/issues/228215869.
|
||||||
|
// For now, swallow the exception.
|
||||||
|
}
|
||||||
serverCanTranslate = false
|
serverCanTranslate = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue