I have a function that can vary depending on the time it takes to complete. I would like to display a progress dialog while this function works.
I know that you can use "Thread" to achieve this. Can someone point me in the right direction for this?
EDIT: Here is the code I'm using:
private class LongOperation extends AsyncTask<String, Void, String>
{
ProgressDialog dialog;
public Context context;
@Override
protected String doInBackground(String... params) {
if (!dialog.isShowing())
dialog.show();
return null;
}
@Override
protected void onPostExecute(String result) {
dialog.dismiss();
}
@Override
protected void onPreExecute()
{
dialog = ProgressDialog.show(context, "Working", "Getting amenity information", true);
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
This is the Asnyc class. The user selects an option from the menu, and this is done:
longOperation.execute("");
GetAmenities(Trails.UserLocation);
source
share