I have an application which uses polling to fetch the data and verify whether any of my data is updated/deleted. Polling takes place in the background. If the user tries to navigate to some screen and if in the background thread the common resource (accessed throughout the application) gets deleted and the viewmodel in which the user has navigated tries to access this resource, the app crashes.
There are too many viewmodels where this scenario can occur.
My approach :- Block the UI at the start of polling. If we find that the data is not deleted, we will immediately unblock. If deleted, we will unblock after polling. By doing this, we are safe that the user won't be able to navigate anywhere and the app won't crash if the data is deleted.
Can anyone suggest a better approach for this?