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_2 extends Activity {
	Button btn;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_2);
        
        final TextView myTextView2 = (TextView) findViewById(R.id.textView2);
        
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
        	return;
        }
        String myText2 = extras.getString("mText");
        myTextView2.setText(myText2);
        
	    btn=(Button) findViewById(R.id.button2);
        btn.setOnClickListener(new OnClickListener() {
        	public void onClick(View view) {
        		myTextView2.setText("RETURN DATA");
        		finish();
        	}
        });
    }

	@Override
	public void finish() {
	    Intent data = new Intent();
	    TextView myTextView2 = (TextView) findViewById(R.id.textView2);
	    String myText = myTextView2.getText().toString();
	    data.putExtra("returnData", myText);
	    setResult(RESULT_OK, data);
	    super.finish();
	}
}