문제

I am using onActivityResult() and onPause() methods in one activity. Now the problem is that whenever onActivityResult() fires, it calls onPause() in the end and so application gets close. How to prevent this problem ? Code :

@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();
}
도움이 되었습니까?

해결책

Please use the boolean variable and activate it onActivityForResult method.

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

다른 팁

Why you are calling finish(); on onPause(). Remove that.

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

When you call finish() caller Activity will be destroyed, so when called Activity finishes the task your app is closing, because there is no Activity (any more) which will handle the result.

So simply remove finish()

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top