سؤال

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