Search code examples
javaandroiduser-interfaceauthenticationprogressdialog

Is using ProgressDialog recommended for login?


I have a login activity where once the login button is pressed a http request will be sent to an api to verify the credentials.

The problem I face is that the button can be pressed multiple times and getting a response back from this task can sometimes take a while.

My solution was to add a ProgressDialog to block the UI. However, I come to find out that ProgressDialog is deprecated. I did some research and it seems that the reason it was deprecated was exactly because the blocking of UI is not optimal for most scenarios.

So I ask, is using ProgressDialog recommended for login scenarios? If not, what would be the best method to handle a login activity when getting a response back from the API may take longer than expected?


Solution

  • You could create a custom "Button" with a disabled/enabled state. When the user clicks the button use disable the button, clear the text and show the progress bar.

    I think this one is a more elegant way to show the loading progress.

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">
    
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/progressBar"
            android:layout_centerInParent="true"
            />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Connect"
            />
    </RelativeLayout>