I have custom dialog for login in my application. I also added progressbar to it and made invisible. When user hits’ button I call AsyncTask to process http login. I control progressbar from AsyncTask. All looks good, but while AsyncTask running – dialog completely responsive. I can change fields, I can click buttons, etc. I see 3 choices:
-
Before running asynctask I will disable all controls. But how do I know when finished? Is there callback I can use?
-
Make login window Activity and show Progress dialog.
-
?
Please let me know what is the proper way to handle this scenario
here is async task. I’m trying to make it generic where I pass url and body and return http response:
private class RESTService extends AsyncTask<String, Integer, String>
{
//TODO: Add text to progress bar and add custom artwork
ProgressBar progress;
Dialog dialog;
Activity activity;
public RESTService(ProgressBar p, Dialog d, Activity a)
{
progress = p;
}
@Override
protected String doInBackground(String... stuff)
{
String url = stuff[0];
String post = stuff[1];
try
{
Thread.sleep(15000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
return "done";
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
if (dialog != null)
{
}
if (progress != null)
{
progress.setVisibility(View.VISIBLE);
}
}
@Override
protected void onPostExecute(String s)
{
super.onPostExecute(s);
if (progress != null)
{
progress.setVisibility(View.GONE);
}
}
}
What I ended up doing – popping AlertDialog, creating interface for AsyncTask listener and calling parent caller on task completion.