Show ProgressDialog Android
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
ProgressDialog was once the standard Android way to show blocking progress, but it is now a legacy API and not the recommended choice for modern apps. If you are maintaining old code, you may still need to understand how it works. For new code, an inline ProgressBar, a custom dialog, or a loading state driven by your view model is the better design.
The Legacy ProgressDialog Pattern
Older Android code often looked like this:
This worked, but it encouraged modal, blocking UI and could easily create leaks or lifecycle bugs if the activity rotated or finished while the dialog was still showing.
Why It Fell Out of Favor
A blocking spinner dialog is rarely the best user experience. It interrupts the whole screen, hides context, and often communicates less clearly than inline loading states. On Android, the move away from ProgressDialog is really about UI architecture and lifecycle safety, not just API fashion.
Problems with the old pattern include:
- dialog leaks on configuration change
- awkward dismissal timing
- inaccessible or unclear UX
- difficulty modeling loading, success, and error as explicit UI state
Modern Approach: Inline ProgressBar
For most screens, keep the user on the screen and show loading inside the layout.
Then toggle visibility in code:
This is simpler, more lifecycle-friendly, and usually better for the user.
Use a Custom Dialog Only When the Interaction Truly Requires It
Sometimes you do want a modal loading dialog, for example during a short, blocking confirmation step. In that case, build it with modern dialog APIs and an embedded ProgressBar instead of relying on ProgressDialog.
This still needs lifecycle care, but it avoids the deprecated API and makes the UI contract explicit.
Tie Loading to View State
The best long-term pattern is to drive progress UI from state, not from ad hoc calls scattered around network callbacks.
For example:
When the screen state is Loading, show the spinner. When it is Content, hide it. This scales much better than manually calling show() and dismiss() from many places.
Indeterminate Versus Determinate Progress
Use an indeterminate spinner when you do not know how long the task will take. Use a determinate horizontal progress bar when you can measure progress meaningfully, such as file upload percentage.
For determinate progress:
Picking the wrong kind of progress indicator makes the UI feel unreliable even when the code is correct.
Common Pitfalls
The biggest mistake is using a modal progress dialog for routine loading that should be shown inline. Another is forgetting that old ProgressDialog code is vulnerable to activity lifecycle issues such as rotation and destruction. Developers also often show an indeterminate spinner for long tasks that should report actual progress. Finally, loading UI that is not driven by screen state tends to become inconsistent and difficult to maintain.
Summary
- '
ProgressDialogis a legacy Android pattern and should not be the default in modern apps.' - For most screens, use an inline
ProgressBarinstead of a blocking dialog. - If a modal experience is required, build it with a regular dialog and a
ProgressBar. - Model loading as UI state rather than scattered show and dismiss calls.
- Choose determinate progress only when you can report meaningful completion percentages.
Related reading
- Show search bar in navigation bar without scrolling on iOS 11
- Sign APK without putting keystore info in build.gradle
- Silent Push Notification in iOS 7 does not work
- Silent pushes not delivered to the app on iOS 11
- Simple and clean way to convert JSON string to Object in Swift
- Simple and clean way to convert JSON string to Object in Swift
- Simple Android grid example using RecyclerView with GridLayoutManager like the old GridView
- Simple Android RecyclerView example
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.