为什么我的应用程序停止显示进度对话框?

Why does my app stop showing the progressdialog?

我已经创建了一个应用程序,用于通过 volley 从服务器接收图像并在我的应用程序中使用 glide 显示在 recyclerview 中,我的应用程序有进度对话框并在应用程序使用 glide 从服务器下载图像时显示进度,但我的应用程序经常停止进行并且不' 像下面的屏幕截图一样工作

我必须关闭应用程序并再次打开它这个问题的解决方案你可以在下面看到我的代码

 RecyclerView recycler_view;
 static final String url="";
 ArrayList<Image> images;
 GalleryAdapter mAdapter;
 ProgressDialog pd;
 public static Button btn_buy;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

recycler_view=(RecyclerView)findViewById(R.id.recycler_view);
btn_buy=(Button)findViewById(R.id.btn_buy);


pd=new ProgressDialog(this);
pd.setCancelable(false);

images=new ArrayList<>();
mAdapter=new GalleryAdapter(getApplicationContext(),images);


RecyclerView.LayoutManager mLayoutManager=new 
GridLayoutManager(getApplicationContext(),2);
recycler_view.setLayoutManager(mLayoutManager);

recycler_view.setAdapter(mAdapter);

ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
1);

recycler_view.addOnItemTouchListener(new 
GalleryAdapter.RecyclerTouchListener(getApplicationContext(),recycler_view, 
new GalleryAdapter.ClickListener() {
@Override
public void onClick(View view, int position) {

Bundle bundle=new Bundle();
bundle.putSerializable("images",images);
bundle.putInt("position",position);



FragmentTransaction ft=getFragmentManager().beginTransaction();

SlideshowDialogFragment newFragment=SlideshowDialogFragment.newInstance();
newFragment.setArguments(bundle);
newFragment.show(ft,"slideshow");


}

@Override
public void onLongClick(View view, int position) {

}
}));

btn_buy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,IABactivity.class);
startActivity(intent);

}
});


fetchImages();
}

@Override
public void onRequestPermissionsResult(int requestCode,
                                     String permissions[], int[] grantResults) {
switch (requestCode) {
case 1: {

// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

      // permission was granted, yay! Do the
      // contacts-related task you need to do.
    } else {

      // permission denied, boo! Disable the
      // functionality that depends on this permission.
      Toast.makeText(MainActivity.this, "دسترسی به حافظه داخلی لغو شد!!!", Toast.LENGTH_LONG).show();
    }
    return;
  }

  // other 'case' lines to check for other
  // permissions this app might request
}
}



public void fetchImages()
{

pd.setMessage("Please wait ...");
pd.show();


StringRequest req = new StringRequest(url,
  new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
      Log.d("", response.toString());
      pd.hide();

      images.clear();
      try {
        JSONObject object = new JSONObject(response);
        JSONArray dataArray = object.getJSONArray("data");

        for (int i = 0; i < dataArray.length(); i++) {
          JSONObject dataObject = dataArray.getJSONObject(i);

          Image image = new Image();
          image.setName(dataObject.getString("name_client"));

          // JSONObject url = object.getJSONObject("url");
          image.setSmall(dataObject.getString("small"));
          image.setOriginal(dataObject.getString("orginal"));
          image.setTimestamp(dataObject.getString("timestamp"));

          images.add(image);

        }
      } catch (JSONException e) {
        e.printStackTrace();
      }

      mAdapter.notifyDataSetChanged();
    }
  }, new Response.ErrorListener() {
  @Override
  public void onErrorResponse(VolleyError error) {
    Log.e("", "Error: " + error.getMessage());
    pd.hide();
  }
});


AppController.getmInstance().addToRequsetQueue(req);

}
}

使用 pd.dismiss() 代替 pd.hide()

而不是 pd.hide() 使用 pd.dismiss()