Modal HUD on asynctask
android
Solution
Use AsyncTask :
public class MyAsyncTask extends AsyncTask<Void, Void, Result>{
private Activity activity;
private ProgressDialog progressDialog;
public MyAsyncTask(Activity activity) {
super();
this.activity = activity;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = ProgressDialog.show(activity, "Loading", "Loading", true);
}
@Override
protected Result doInBackground(Void... v) {
//do your stuff here
return null;
}
@Override
protected void onPostExecute(Result result) {
progressDialog.dismiss();
Toast.makeText(activity.getApplicationContext(), "Finished.",
Toast.LENGTH_LONG).show();
}
}
Call it from the activity:
MyAsyncTask task = new AsyncTask(myActivity.this);
task.execute();
Problem
I am working on something in Android. There will be a menu, when accessed, requests a fairly large list of users from a server (500+) and takes about 5 seconds. During this time, the application freezes. How do I go about showing a progress hud (like MBProgressHud) where the user is aware something is happening and can't touch out of it until it is complete. MBProgressHud: