반응형

InformationInput .java

 

package com.androidhuman.IntentTest;

 

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

public class InformationInput extends Activity {

 

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

final Button requestInfo = (Button)findViewById(R.id.requestInfo);

 

// 버튼을 클릭할 경우

requestInfo.setOnClickListener(new Button.OnClickListener(){

public void onClick(View v){

Intent intent = new Intent(InformationInput.this,InformationProc.class);

 

// Sub_Activity 호출

startActivityForResult(intent, 1); 

}

});

}

 

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data){

super.onActivityResult(requestCode, resultCode, data);

TextView name_view = (TextView)findViewById(R.id.name_view);

TextView digit_view = (TextView)findViewById(R.id.digit_view);

 

// 액티비티가 정상적으로 종료되었을 경우

if(resultCode==RESULT_OK) {

// InformationInput에서 호출한 경우에만 처리합니다.

if(requestCode==1) {

// 받아온 이름과 전화번호를 InformationInput 액티비티에 표시name_view.setText(data.getStringExtra("data_name"));

digit_view.setText(data.getStringExtra("data_digit"));

}

}

}

}

 

InformationProc .java

 

package com.androidhuman.IntentTest;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

public class InformationProc extends Activity {

 

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.informationproc);

Button input_info = (Button)findViewById(R.id.inputinfo);

input_info.setOnClickListener(new OnClickListener(){

 

//버튼을 클릭하면

public void onClick(View v) { 

// 이 액티비티를 시작하게 한 인텐트를 호출

Intent intent = getIntent(); 

EditText name_input = (EditText)findViewById(R.id.name_input);

EditText digit_input = (EditText)findViewById(R.id.digit_input);

intent.putExtra("data_name",name_input.getText().toString());

intent.putExtra("data_digit", digit_input.getText().toString());

 

// 추가 정보를 넣은 후 다시 인텐트를 반환합니다.

setResult(RESULT_OK,intent);

// 액티비티 종료 

finish(); 

}

});

}

}

 

참고 : http://androidhuman.tistory.com/125

반응형

+ Recent posts