user2431992
user2431992

Reputation:

onPause fires directly when called onActivityResult

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();
}

Upvotes: 1

Views: 368

Answers (2)

nilesh patel
nilesh patel

Reputation: 832

Please use the boolean variable and activate it onActivityForResult method.

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

Upvotes: 1

Pankaj Kumar
Pankaj Kumar

Reputation: 82978

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()

Upvotes: 1

Related Questions