Oddly enough, I don't seem to have found an answer regarding this.
I've been trying for a while to use the Android Room Persistence Library to store persistent data across app terminations, and one of the big sticking points for me is its asynchronous (results aren't ready the moment the database call returns) nature, requiring work to access the databases be done on separate threads instead, which is done in order to maximize performance.
And this doesn't seem to be a problem now except for one thing: it seems to me that in at least one big, important area, this is difficult to see how to do, at least when other concerns are taken into account, and that is the one of initializing a UI element, like an Activity or Fragment where the information displayed in it to the user and/or its state have to be loaded from the database. The "additional concerns" are related to those touched upon here:
Is it good practice implementing Parcelable on a Room database entity?
in particular, I am using a design setup that generally follows the principles mentioned in the answer there: namely, that I have a set of "model" objects which are designed to be agnostic as to the underlying database system we are using.
The problem, however, of course, is trying to figure out what to do on first initialization, when we first bring up the app and/or UI feature. The model object has to be created here, and ideally, it should be primed with data from the existing database. And that means we have to do a load from the database, which is also asynchronous. Yet, we cannot make the UI feature until we have that data that is supposed to fill it, and thus we have to wait.
And this runs into issues of good design practices: which are my primary question. In particular, I want to ensure the UI code knows - in line with what is mentioned in the linked answer - as little as possible about the underlying database implementation and that means it cannot be "informed", so to speak, of quirks like that some databases demand asynchronous accesses while others may not. And the current implementation has "synchronous" semantics - a "LOAD" call to the abstract database (called a "repository" in the question above) is expected to furnish data immediately, and likewise, after a "SAVE" call, an immediately-subsequent "LOAD" call should be expected to return the data just "SAVE"d. If we use a callback, then that means we have to do that in the UI code, which means we break the abstraction barrier, which is clearly poor design/coding practice and a basic OOP "no-no".
So this makes me wonder: is it "OK" practice for this particular instance to "cheat" by starting an AsyncTask or similar and then waiting with its "get()" method underneath the model object to fake synchronous access, or is this, as my smell test seems to be telling me (on the logic that, generally, if you're trying to break or work around a well-reasoned design feature, you're probably doing something wrong), a no-no, and if so, what is the "correct" way to handle this?
Moreover, none of the reference material I've found seems to address this even though it seems like such a basic and important use case, which is extremely aggravating and headpoppy.