Reputation: 409
In my android application calling an API continuously in a loop then Progress Dialog make a shadow like appearance. I think the issue is that multiple dialog running..help me to avoid this shadow. Code given below:
for(int i = indexOfSelectedId + 1 ; i < photoall_id.size(); i++)
{
all_postid.add(photoall_id.get(i));
url = URLS.BASEURL + "mobile_api.php?action=post&post_id=" +posoall_id.get(i)+user_id="+userid;
new GetImage().execute(url);
}
private class GetImage extends AsyncTask<String, Void, ArrayList<String>> {
String json = null;
ProgressDialog dialog;
@Override
protected void onPreExecute() {
all_data=new ArrayList<>();
dialog = new ProgressDialog(FullScreenActivity.this);
dialog.setMessage("Loading Image...");
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.show();
super.onPreExecute();
}
@Override
protected void onPostExecute(ArrayList<String> aVoid) {
dialog.dismiss();
all_url.add(aVoid.get(0));
}
@Override
protected ArrayList<String> doInBackground(String... params) {
JSONReader reader = new JSONReader();
json = reader.getJsonGET(params[0]);
if (json != null) {
try {
JSONObject object = new JSONObject(json);
if (object.getJSONArray("posts").getJSONObject(0).getInt("count") != 0) {
photo_url = object.getJSONArray("posts").getJSONObject(0).getString("photo_url");
}
}
Suggest a solution.Thanks in advance
Upvotes: 0
Views: 270
Reputation: 407
To avoid multiple dialog to show:
public void showProgress(String msg)
{
if(dialog == null){
dialog = new ProgressDialog(this);
dialog.setTitle(null);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
}
if(dialog.isShowing())
{
dialog.dismiss();
}
dialog.setMessage(msg);
dialog.show();
}
public void dismissProgress()
{
if(dialog != null && dialog.isShowing())
dialog.dismiss();
}
Upvotes: 2