Glide导致图像文件崩溃删除

时间:2017-08-29 06:10:09

标签: android android-intent android-activity android-glide

我的应用程序有一个活动,显示从Gridview项目收到的图像onClick通过Intent ...

我使用Glide& amp;将Image加载到ImageView中。我有一个FAB删除该特定图像,但只要我点击FAB,即使我使用Failed to Load Resource返回Gridview&时,Glide也会导致this.finish()崩溃。更新它......

这是代码 -

public class Img extends AppCompatActivity {

    private File f;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.img);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);


        Intent i = getIntent();
        String p = i.getExtras().getString("pos");

        f = new File (p);

        ImageView img = (ImageView) findViewById(R.id.photo);

        FloatingActionButton dlt = (FloatingActionButton) findViewById(R.id.dlt);

        dlt.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Img.this);

                    builder.setTitle("Sure to Delete this Image?")
                        .setNegativeButton("Nope", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        })

                        .setPositiveButton("Delete", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                deletePIC();
                                Toast.makeText(Img.this, "Image Deleted", Toast.LENGTH_SHORT)
                                    .show();
                            }
                        });
                    builder.create()
                        .show();


                }
            });

        Glide.with(Img.this)
            .load(f)
            .into(img);
    }


    public void deletePIC(){

        Intent i = new Intent();
        int pos = i.getExtras().getInt("pos");
        i.putExtra("pos", pos); 
        setResult(Activity.RESULT_OK, i); 
        if (f.exists()){
            f.delete ();
        }
        Img.this.finish();
    }

0 个答案:

没有答案