1

I just weird, why i got wrong value after put extra boolean. Very weird. I know other post already answer about put extra, but this post i don't know why i got wrong value.

This is my first activity. Just short code.

btnActivity.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), ActivitySecond.class);
            startActivityForResult(i, 1);
        }
    });

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

    if(requestCode==1)
    {
        boolean thisAnwser = getIntent().getBooleanExtra("thisAnwserBoolean",false);
        Log.i("this boolean is","Answer: "+thisAnwser); //this log, i got false..

        if(thisAnwser){
            Log.i("Good this true","yes");
        }


    }
}

This is second activity

Intent intent = new Intent();
intent.putExtra("thisAnwserBoolean", true); // when i try log, i got true.
setResult(1,intent);
finish();
John Joe
  • 12,412
  • 16
  • 70
  • 135
MAS. John
  • 582
  • 6
  • 22
  • You're looking at the wrong `Intent`. You want to get the extras from the `Intent data` parameter in the `onActivityResult()` method. – Mike M. May 05 '17 at 02:56
  • yes, u are right .. Thanks Sir – MAS. John May 05 '17 at 03:01
  • `Bundle extra=data.getExtras(); boolean thisAnwser = extra.getBoolean("thisAnwserBoolean"); or boolean thisAnwser = data.getExtras().getBoolean("thisAnwserBoolean");` – MAS. John May 05 '17 at 03:03

2 Answers2

2
 boolean thisAnswer = getIntent().getExtras().getBoolean("thisAnwserBoolean");

You are adding a false, so you will always get false. Remove the false

John Joe
  • 12,412
  • 16
  • 70
  • 135
2

try this:

Boolean yourBool = getIntent().getExtras().getBoolean("yourBoolName");
Kaushal28
  • 5,377
  • 5
  • 41
  • 72
  • Thanks but i already got the answer.. This one `Bundle extra=data.getExtras(); boolean thisAnwser = extra.getBoolean("thisAnwserBoolean"); or boolean thisAnwser = data.getExtras().getBoolean("thisAnwserBoolean");` – MAS. John May 05 '17 at 03:03