package gr.mybook.myexplicitintent;

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.TextView;

public class Activity_1 extends Activity {
	private static final int REQUEST_CODE = 5;
	Button btn;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_1);

	    final TextView myTextView1 = (TextView) findViewById(R.id.textView1);

	    btn=(Button) findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener() {
        	public void onClick(View view) {
        	    Intent intent = new Intent(Activity_1.this, Activity_2.class);
    		    String myText = myTextView1.getText().toString();
    		    intent.putExtra("mText", myText);
        	    startActivityForResult(intent, REQUEST_CODE);
        	}
        });
    }
    
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
    	if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
    		TextView myTextView1 = (TextView) findViewById(R.id.textView1);
    		String returnText = data.getExtras().getString("returnData");
    		myTextView1.setText(returnText);
    	}
    }
}