Frage

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();
}
War es hilfreich?

Lösung

Please use the boolean variable and activate it onActivityForResult method.

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

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top