One of AIS’s recent projects involved development of an iPhone application using MonoTouch. This application made significant use of web services, some of which could take 10’s of seconds to return (Yes, we were moving a lot of data for this particular application… there is just no easy way to deal with “historical data”).
Rather than just locking the UI for the duration of the activity, we wanted to display a user notification that something was actually happening in the background. In addition, we wanted to disable the UI so the user did not inadvertently believe they could tap anything.
Our goals:
1. Display a “long running operation” notification to the user
2. Lock the primary UI to prevent unwanted unexpected user interactions
3. The component must be reusable
To accomplish this feat of programming, we decided to use a UIAlertView with a UIActivityIndicatorView on it. We created the ActivityAlertView class to manage this for us. It allows you to use it in one of 2 ways:
- In a using statement. This will display the ActivityAlertView for the duration that the using statement is in scope:
- Normal instantiation
using(ActivityAlertView alert
= new ActivityAlertView("Logging in, Please wait"))
{
//Code to do while ActivityAlertView is displayed to user
}
ActivityAlertView alert = new ActivityAlertView;
alert.Show("Logging in, Please wait");
//Code to do while ActivityAlertView is displayed to user
alert.Dismiss();
Here are a few screenshots of the attached demo project.
Download the sample project and source code from this link