2011-03-30 4 views

답변

12

귀하가 여기에 Intent#putExtra(String, String).

을 찾고 미리

Intent myIntent = new Intent(mycurentActivity.this, secondActivity.class); 
startActivity(myIntent); 

감사합니다 두 번째 의도를 전달하려는 것은 예입니다 :

Intent myIntent = new Intent(mycurentActivity.this, secondActivity.class); 
myIntent.putExtra("key", myEditText.Text.toString(); 
startActivity(myIntent); 

수신 할 때 ntent 당신은 다시 추출 할 수 있습니다 :

String text = myIntent.getStringExtra("key"); 

(http://developer.android.com/reference/android/content/Intent.html#getStringExtra(java.lang.String))

+1

초 활동 후, Eclipse는 로컬 변수 의도를 생성하고 초기화 나에게 묻는다 null로; 다음 코드를 실행하면 빈 화면이 나타납니다. 미리 감사드립니다. 최상의 regrads – User616263

+1

로컬 변수 int를 만들어야합니다. 당신이 그것을 한 코드를 보여주십시오. – RoflcoptrException

+0

개체를 전달할 방법이 없습니까? 이 방법은 정말 옳은 일이다. – Vincent

0

첫 번째 활동

Intent myIntent = new Intent(rechercheCP.this, XMLParsing.class); 
        myIntent.putExtra("key", autoComplete.getText().toString()); 
        startActivity(myIntent); 

첫 번째 활동에서 두 번째 활동

TextView a; 
String text = myIntent.getStringExtra("key"); 
a = new TextView(this); 
    a.setText(text); 
    layout.addView(a); 
0

//... 
final static int EDIT=0; 
//...(action trigger) 
public void onClick(View v) { 
    // TODO Auto-generated method stub 

    Intent intent; 
    intent = new Intent().setClass(mycurentActivity.this, secondActivity.class); 
    startActivityForResult(intent, EDIT); 
} 
//... 

및나중에 첫 번째 활동

//... 
protected void onActivityResult(int requestCode, int resultCode, Intent data){ 
    switch(requestCode){ 
     case EDIT: 
      if(resultCode == RESULT_OK){ 
      String text = data.getStringExtra("key"); 
      //do whatever with the text... 
     }else if(resultCode == RESULT_CANCELED){ 
     } 
    break; 
    } 
} 
//... 

당신이 그것을 쓰기처럼 코드를 넣어

//... 
Intent intent = new Intent().setClass(secondActivity.this, mycurentActivity.class); 
intent.putExtra("key", myEditText.getText().toString); 
setResult(RESULT_OK, intent); 
finish(); 
//... 
관련 문제