1
edit
Changes
no edit summary
9.1.5 Now it is time to build your project so that our id's will be generated.
=== 9.2 Creating EmailContactActivity.java === 9.2.1 Lets add our private variables and that we get the right layout once it has been started.<source lang="java">private EditText sEmailTo; private EditText sSubject; private EditText sBody; private Button btnSend; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.email); setContentView(R.layout.email);</source> 9.2.2 If we capture the intent now we will be able to retrieve the saved email address of the selected student.<source lang="java">// get the intent sent to this class Intent i = this.getIntent(); sEmailTo = (EditText) findViewById(R.id.editEmailTo); //sEmailTo.setText(i.getStringExtra("oldEmail")); sSubject = (EditText) findViewById(R.id.editEmailSubject); sBody = (EditText) findViewById(R.id.editEmailBody);</source> 9.2.3 In order to have our application send the email we must implement a button.<source lang="java">btnSend.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (v.getId() == R.id.emailSend) { finish(); } } }); }</source> 9.2.4 We must now override the finish() method and send the email.<source lang="java">@Override public void finish() { // Setup the recipient in a String array String[] mailto = { sEmailTo.getText().toString() }; // Create a new Intent to send messages Intent sendIntent = new Intent(Intent.ACTION_SEND); // Add attributes to the intent sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto); sendIntent.putExtra(Intent.EXTRA_SUBJECT, sSubject.getText().toString()); sendIntent.putExtra(Intent.EXTRA_TEXT, sBody.getText().toString()); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, "SendMail")); super.finish(); }</source>