I'm facing a problem with Async operation when App starts.
During OnCreate
, I start a background operation that call a web service to test if the service is available. In the activity, I have a label with Connecting...
text. When the async operation completes, the label's text is changed to OK
or No service
.
Now the question is: can I show to my user that an async operation is in progress?
I cannot figure out how I can use another async operation can show some animation while the server responds and complete the second async operation when the first completes.
You would ideally create a custom View
which renders the animation (or use the SDK built-in indeterminate ProgressBar
) and place it in your layout, with its visibility
set to ViewStates.Gone
.
Before the async operation is launched, the view's visibility
is set to ViewStates.Visible
, and after the async operation completes, the visibility
is again set to Gone
. You may even remove the view from the layout if you want after the async operation completes.
You'd have something like (pseudo-C#)
async void OnCreate()
{
// Some code (get references to views, etc.)
progressView.Visibility = ViewStates.Visible;
var asyncResult = await SomeAsyncOperation();
progressView.Visibility = ViewStates.Gone;
// Some more code
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.