繁体   English   中英

在Android中调用没有finish()的新意图后,活动停止

[英]Activity stopped after called new intent without finish() in Android

当我使用startActivityForResult()在一个活动中调用新意图来选择图像时,

但是应用程序在从库中挑选照片后停止,可能是在调用新意图后停止的活动。

    Intent image_pick_intent = new Intent(Intent.ACTION_PICK);
    image_pick_intent.setType("image/*");
    startActivityForResult(image_pick_intent, Request.REQUEST_IMAGE_PICK);

以前我没有用相同的代码面对这个问题,任何想法为什么我已经触发了这个以及如何在图像选择之后回到活动的OnActivityResult?

谢谢 :)

你正在运行哪个操作系统版本? 您是否已根据操作系统版本检查了您的访问权限? 检查清单。

试试这段代码。

首先下载photoutil.jar并粘贴到project- > apps-> libs中。

final int GALLERY_REQUEST = 22131;


startActivityForResult(galleryPhoto.openGalleryIntent(), GALLERY_REQUEST);


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {

        if (requestCode == GALLERY_REQUEST) {

            Uri uri = data.getData();
            galleryPhoto.setPhotoUri(uri);
            String photoPath = galleryPhoto.getPath();
            selectedPhoto = photoPath;
            try {
                Bitmap bitmap = ImageLoader.init().from(photoPath).getBitmap();
                imgProof.setImageBitmap(bitmap);

            } catch (FileNotFoundException e) {
                Toast.makeText(getApplicationContext(),
                        "Something Wrong while choosing photos", Toast.LENGTH_SHORT).show();
            }

        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM