Android AsyncTask Progress bar
Please try this
public class LoadData extends AsyncTask<Void, Void, Void> {
ProgressDialog progressDialog;
//declare other objects as per your need
@Override
protected void onPreExecute()
{
progressDialog= ProgressDialog.show(YourActivity.this, "Progress Dialog Title Text","Process Description Text", true);
//do initialization of required objects objects here
};
@Override
protected Void doInBackground(Void... params)
{
//do loading operation here
return null;
}
@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
progressDialog.dismiss();
};
}
You can call this using
LoadData task = new LoadData();
task.execute();
AsyncTask with a ProgressDialog and Progress Bar
Add Style to your progress dialog with before you show it .setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
Android custom progress indicator while doing AsyncTask
If you need more control over your ProgressBar, you can use WindowManager to add a view on top of everything. It can be done without any additional layout, activities or windows. You can control animation, touches, position and visibility just like in case of regular view. Fully working code:
final ProgressBar view = new ProgressBar(TestActivity.this);
view.setBackgroundColor(0x7f000000);
final LayoutParams windowParams = new WindowManager.LayoutParams();
windowParams.gravity = Gravity.CENTER;
windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
windowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
windowParams.format = PixelFormat.TRANSLUCENT;
windowParams.windowAnimations = 0;
new AsyncTask<Integer, Integer, Integer>() {
public void onPreExecute() {
// init your dialog here;
getWindowManager().addView(view, windowParams);
}
public void onPostExecute(Integer result) {
getWindowManager().removeView(view);
// process result;
}
@Override
protected Integer doInBackground(Integer... arg0) {
// do your things here
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}.execute();
Related Topics
How to Create a Relativelayout Programmatically with Two Buttons One on Top of the Other
How to Display Progress While Loading a Url to Webview in Android
The Import Android.Support.V7 Cannot Be Resolved
Android: How to Change Checkbox Size
Tabhost with Fragments and Fragmentactivity
How to Limit the Height of Spinner Drop Down View in Android
Getting the Battery Current Values for the Android Phone
Error: Resource Android:Attr/Fontvariationsettings Not Found
Causing Outofmemoryerror in Frame by Frame Animation in Android
Is 'Shouldoverrideurlloading' Really Deprecated? What How to Use Instead
How to Know My Android Application Has Been Upgraded in Order to Reset an Alarm
What Is the Intent of the Methods Getitem and Getitemid in the Android Class Baseadapter
Lazy Load Images on Listview in Android(Beginner Level)
Detect When Recyclerview Reaches the Bottom Most Position While Scrolling
Compiling the Latest Openssl for Android
Is Secure.Android_Id Unique for Each Device