startActivityForResult返回parentactivity而不是activity本身

时间:2013-11-16 13:56:09

标签: android image parent start-activity onactivityresult

我有活动A,它启动活动B,活动B启动,然后使用Galleryapp来选择图像。我的问题是,当我选择图像(或按取消)时,我返回活动A,虽然活动B开始了这个过程,应该处理整个结果。

此外,在我返回活动A后,Eclipse不再跳入断点。然后我启动活动B,之后按下按钮再次打开galleryapp,返回正确的结果,一切正常。

有谁可以向我解释这里发生了什么?我正在搜索相当一段时间,但我得到的唯一提示是,由于内存问题,活动B可能已从堆栈中删除。但是为什么要删除活动B而不是活动A? 我确实需要修复此问题,以便在选择图像时,galleryapp每次都返回到活动B.

@Override
public void onClick(View v) {
    if(v.getId() == btnOk.getId())
    {
        handleOKClick();
    }
    else if(v.getId() == channelThumbnail.getId())
    {
        Intent pickImageIntent = new Intent(Intent.ACTION_PICK);
        pickImageIntent.setType("image/*");
        startActivityForResult(pickImageIntent, PICK_IMAGE_RESULT);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == PICK_IMAGE_RESULT && resultCode == RESULT_OK)
    {
        Uri selectedImage = data.getData();
        try {
            InputStream imageStream = getContentResolver().openInputStream(selectedImage);
            Bitmap bmp = BitmapFactory.decodeStream(imageStream);

            DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
            //Set Maximum size of an Thumbnail to 512x512
            bmp = Utility.limitBitmapToBoundries(bmp, 256, 256);
            this.channelThumbnail.setImageBitmap(bmp);
            this.channelThumbnail.setBackgroundColor(Color.TRANSPARENT);
            AddYamasChannelActivity.this.curSelectedImage = bmp;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
    }
}

private void handleOKClick()
{
    //Check if Image was already selected, otherwise prompt the user to select an image
    if(this.curSelectedImage == null)
    {
        Utility.showWarningDialog(this, R.string.error, R.string.alertdialog_addyamaschannel_no_image);
        return;
    }

    //Check if Channelname is longer than 3 Characters
    String channelName = et.getText().toString();
    if(channelName.length() >= 3)
    {
        pb.setVisibility(View.VISIBLE);
        et.setEnabled(false);
        btnOk.setEnabled(false);
        AddYamasChannelAsyncTask addYamasChannelAsyncTask= new AddYamasChannelAsyncTask();
        addYamasChannelAsyncTask.execute(channelName, googleAccountName);
    }
    else
        Toast.makeText(AddYamasChannelActivity.this, R.string.alertdialog_channelname_too_short, Toast.LENGTH_SHORT).show();

}

0 个答案:

没有答案