2017-05-05 1 views
1

난 이상한, 왜 여분의 불리언 넣어 후 잘못된 값을 가지고. 엄청 이상해. 나는 다른 게시물에 대해 이미 여분의 넣어에 대한 답변을 알고 있지만이 게시물은 내가 왜 잘못 된 가치를 모르겠어요.안드로이드에 여분의 boolen 넣어 잘못된 값을

이것은 첫 번째 활동입니다. 그냥 짧은 코드. 당신은 항상 false를 얻을 수 있도록

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


    } 
} 

이, 두 번째 활동

Intent intent = new Intent(); 
intent.putExtra("thisAnwserBoolean", true); // when i try log, i got true. 
setResult(1,intent); 
finish(); 
+0

을 당신은 잘못된'Intent' 찾고 있습니다. onActivityResult() 메소드의 Intent data 매개 변수에서 추가 정보를 얻고 싶습니다. –

+0

네, 맞습니다 .. 감사합니다. –

+0

'Bundle extra = data.getExtras(); 부울 thisAnwser = extra.getBoolean ("thisAnwserBoolean"); 또는 부울 thisAnwser = data.getExtras() getBoolean ("thisAnwserBoolean");. ' –

답변

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

당신은 false를 추가하는 것입니다. false

+0

가 나는 또한 동일한 여전히 거짓있어 –

+1

감사하지만 난 이미 답을 가지고, 이와 같은 시도,이 '번들 추가 = 데이터 .getExtras(); 부울 thisAnwser = extra.getBoolean ("thisAnwserBoolean"); 또는 부울 thisAnwser = data.getExtras(). getBoolean ("thisAnwserBoolean"); ' –

+0

잘 해결했습니다. –

1

이 시도 제거

Boolean yourBool = getIntent().getExtras().getBoolean("yourBoolName"); 
+0

고마워요.하지만 이미 답을 얻었습니다.이 하나'Bundle extra = data.getExtras(); 부울 thisAnwser = extra.getBoolean ("thisAnwserBoolean"); 또는 부울 thisAnwser = data.getExtras(). getBoolean ("thisAnwserBoolean"); –

관련 문제