How to initiate background process(configuration) and show progress indicator until it finishes?
Yes, it could be achieved, You can set the visibility of progressbar to visible, and visibility of other controls is invisible in this Activity, If you have finish connect several devices using API calls, you can set the visibility of progressbar to invisible , other controls visibility to visible like this GIF.
I add a Task delay in this demo. you can replace your code about the connectseveral devices using API calls, but these code should be run in a thread, if progress of connection is done, you can set other controls visibility to visible, set the visibility of progressbar to invisible.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar android:id="@+id/progress_bar" android:layout_width="250dp" android:layout_height="250dp" android:indeterminate="false" android:max="100" android:layout_centerInParent="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:text="click" android:visibility="invisible" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ddddddddd" android:id="@+id/textView1" android:layout_toRightOf="@id/button1" android:visibility="invisible" /> </RelativeLayout> protected async override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); ProgressBar progress_bar = FindViewById<ProgressBar>(Resource.Id.progress_bar); Button button1 = FindViewById<Button>(Resource.Id.button1); TextView textView1 = FindViewById<TextView>(Resource.Id.textView1); await Task.Delay(4000); progress_bar.Visibility = Android.Views.ViewStates.Invisible; button1.Visibility = Android.Views.ViewStates.Visible; textView1.Visibility = Android.Views.ViewStates.Visible; }
Answers
Based on your description, I think that achieve a forground service is a good choice, then push a notification, show the progress in the notification.
https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/services/foreground-services
Due to you initiate background process, this process is a time-consuming operation, It will make ANR easily(if not run it in service), and foreground service will make sure this initate process could be operated successfully, normally it will be killed by GCM.
Thanks LeonLu...While this seems to be appropriate for my question, I had another query. When the app starts for the first time and I want to connect several devices using API calls; so in order to achieve this I was thinking to show the round progress bar so that the user does not interact with the UI controls. However if the time is unkown, I don't want to hard code the timer...In that instance what would be the appropriate solution?
Thanks again
Yes, it could be achieved, You can set the visibility of progressbar to visible, and visibility of other controls is invisible in this Activity, If you have finish connect several devices using API calls, you can set the visibility of progressbar to invisible , other controls visibility to visible like this GIF.
I add a Task delay in this demo. you can replace your code about the connectseveral devices using API calls, but these code should be run in a thread, if progress of connection is done, you can set other controls visibility to visible, set the visibility of progressbar to invisible.
Awesome..thanks