Can't Access Fragment Views
When the observer is still active on the parent's view, the Can't access Fragment Views error occurs. Even if the view is deleted, LifecycleOwner remains ( Navigating to the next Fragment)
Came Across this error while trying to observe live data through the current viewLifecycleOwner
SOLUTION:
A possible and very simple workaround for this type of problem is to encapsulate the code that causes it in an if statement with the condition to check if the view is null or not.
Wrap Up:
As long as our condition is true, our line of code has a view to which it may connect, making it accessible. However, if not, such a viewpoint becomes disconnected.
Subscribe to my newsletter
Read articles from Arthur Okolo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by