2016-07-22 3 views
1

요청 코드를 사용하여 MainActivity에서 InfomationActivity으로 전화했습니다. 그러나 MainActivity을 반환하면 비활성 상태가됩니다. 여기에 어떤 문제가 있습니까?ResultCode 및 RequestCode가 작동하지 않습니다.

MainActivity에서

하는 requestCode가 사용 InfomationActivity 전화 : InfomationActivity에서

Intent intent = new Intent(MainActivity.this, InfomationActivity.class); 
startActivityForResult(intent, 100); 

을하는 같은 ResultCode 반환 :

 if(btnAlarmInfo.getVisibility() == View.VISIBLE){ 
      //run 
      Log.d("abc", note.getTitle() + "/" + note.getNote() + "/" + note.getDateTime() + "/" + note.getColorBackground()); 
      Log.d("abc", Integer.toString(images.size())); 
      Intent intent = getIntent(); 
      intent.putExtra("title", note.getTitle()); 
      intent.putExtra("note", note.getNote()); 
      intent.putExtra("time", note.getDateTime()); 
      intent.putExtra("color", note.getColorBackground()); 
      intent.putParcelableArrayListExtra("image", images); 
      setResult(3, intent); 
      finish(); 
     }else{ 
      //run 
      Intent intent = getIntent(); 
      intent.putExtra("title", note.getTitle()); 
      intent.putExtra("note", note.getNote()); 
      intent.putExtra("time", note.getDateTime()); 
      intent.putExtra("color", note.getColorBackground()); 
      intent.putExtra("day", note.getDayAlarm()); 
      intent.putExtra("hour", note.getHourAlarm()); 
      intent.putParcelableArrayListExtra("image", images); 
      setResult(4, intent); 
      finish(); 
     } 

그리고 때를 MainActivity 반환 :

로그 캣에서
if(requestCode == 100){ 
     if(resultCode == 3){ 
      //not run ???????? 
      Log.d("abc", "it's me"); 
      String title = data.getExtras().getString("title"); 
      String note = data.getExtras().getString("note"); 
      String time = data.getExtras().getString("time"); 
      String color = data.getExtras().getString("color"); 
      ArrayList<Image> image = data.getParcelableArrayListExtra("image"); 
      Log.d("abc", Integer.toString(image.size())); 
      ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(); 
      for(int i = 0; i < image.size(); i++){ 
       bitmaps.add(image.get(i).getImage()); 
      } 
      Note note1 = new Note(title, note, false, time, color, "", "", bitmaps); 
      this.addNote(note1); 
     }else if(resultCode == 4){ 
      //run 
      String title = data.getExtras().getString("title"); 
      String note = data.getExtras().getString("note"); 
      String time = data.getExtras().getString("time"); 
      String color = data.getExtras().getString("color"); 
      String day = data.getExtras().getString("day"); 
      String hour = data.getExtras().getString("hour"); 
      ArrayList<Image> image = data.getParcelableArrayListExtra("image"); 
      ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(); 
      for(int i = 0; i < image.size(); i++){ 
       bitmaps.add(image.get(i).getImage()); 
      } 
      Note note1 = new Note(title, note, true, time, color, day, hour, bitmaps); 
      this.addNote(note1); 
     } 
    } 

, 난 resultcode = 3 일 때 실행되지 않는지 확인하십시오. 왜 resultcode = 3이면 실행되지 않습니까?

+0

과 4, 괜찮습니다. –

+0

정수 값은이 결과에 적용 할 수 없으므로 비정상적으로 작동 할 수 있으므로 RESULT_OK 만 사용하고 3 또는 4를 int로 사용하여 하나의 매개 변수를 설정하는 것이 좋습니다. 중요한 것은 모든 값을 입력 할 필요가 없습니다. if-else loop 그래서 시도해보십시오. – Vickyexpert

+0

2 건이 처리되면 괜찮습니다.하지만 더 많은 경우가 필요합니까 ??? –

답변

1

결과 코드는 미리 정의 된 값 RESULT_OK, RESULT_CANCELLED 또는 RESULT_FIRST_USER 중 하나를 사용하여 설정 한 것으로 가정합니다.

3과 4와 같은 설정 값은 반드시 여기에 정의 된 동작이있는 것은 아닙니다. 그들이 당신에게 어떤 의미를 가지고 있다면 (그리고 무작위가 아닌), 의도에 따라 또 다른 여분의 것으로 돌려 보내십시오. 그 자리에 RESULT_OK을 사용하십시오.

또한 결과를 전달하기 위해 사용하는 인 텐트의 경우 활동을 시작하는 데 사용한 번호 (getIntent())를 재사용하지 말고 new Intent()을 사용하여 새로 작성하는 것이 좋습니다.

어쨌든 활동 시작 및 결과 얻기를 다루는 this section of the docs을 검토하는 것이 좋습니다.

+0

4 개의 핸들 케이스가 반환되어야합니다. 어떻게해야합니까? –

+0

@KhanhDoan, 처리해야 할 4 가지 사례가있는 경우 결과 코드를 RESULT_OK로 설정 한 다음 반환 의도에있는 사용 사례를 지정하는 int를 전달하는 것이 좋습니다. 그런 다음 귀하의 부름 활동에서 4 가지 사례 중 어느 것이 었는지 확인하기 위해 반품 의도를 확인하십시오. –

관련 문제