I have a login view in an android app that I would like to function synchronously. That is, I want the user to stay on the page until the login rest call completes. If it fails, the user can reenter their id and password. If it is successful they are routed to a welcome page.
Retrofit gives examples of how to make synchronous calls. But it comes with a warning that "synchronous requests trigger app crashes on Android 4.0 or newer. You’ll run into the NetworkOnMainThreadException error." I've seen various responses on stackoverflow including using Otto and Robospice. Others to use homegrown listeners and others to use synchronous requests.
What would be the easiest, safest way to implement this functionality.
You don't need synchronous requests to achieve this..
Synchronous requests are carried out on the main thread. In android the main thread is used for drawing your UI so carrying out a network request on that thread will block your UI hence Android raises an exception .
Asynchronous requests carry out the networking in a separate thread and have callbacks to deliver information back to the main thread. This is what you need.
Here's what the sample code using Retrofit would look like in your case