我在一项活动中使用onActivityResult()onPause()方法。
现在的问题是,每当onActivityResult()触发时,它最终都会调用onPause(),因此应用程序会关闭。
如何预防这个问题?
代码:

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

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
            && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        picturePath = cursor.getString(columnIndex);
        cursor.close();

        ImageView imageView = (ImageView) findViewById(R.id.imgView);
        imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
    }
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

最佳答案

请使用布尔变量并在onActivityForResult方法上将其激活。

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
if(!isActivate)
    finish();
}

关于android - 当调用onActivityResult时,会直接触发onPause,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16812652/

10-12 05:13