Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dzar.activitydua;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- /**
- * SecondActivity defines the second activity in the app. It is launched from an intent
- * with a message, and sends an intent back with a second message.
- */
- public class SecondActivity extends AppCompatActivity {
- /* Unique tag for the intent reply. */
- public static final String EXTRA_REPLY =
- "com.example.android.twoactivities.REPLY";
- /* EditText for the reply */
- private EditText mReply = null;
- /**
- * Initialize the activity.
- * @param savedInstanceState The current state data
- */
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_second);
- /* initialize view variables */
- mReply = (EditText) findViewById(R.id.editText_second);
- /* Get the intent that launched this activity, and the message in
- the intent extra. */
- Intent intent = getIntent();
- String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
- /* Put that message into the text_message TextView */
- TextView textView = (TextView) findViewById(R.id.text_message);
- if (textView != null) {
- textView.setText(message);
- }
- }
- /**
- * Handle the onClick for the "Reply" button. Gets the message
- * from the second EditText, creates an intent, and returns
- * that message back to the main activity.
- *
- * @param view The view (Button) that was clicked.
- */
- public void returnReply(View view) {
- /* Get the reply message from the edit text */
- String reply = "";
- if (mReply != null) {
- reply = mReply.getText().toString();
- }
- /* Create a new intent for the reply, add the reply message to it as an extra,
- set the intent result, and close the activity. */
- Intent replyIntent = new Intent();
- replyIntent.putExtra(EXTRA_REPLY, reply);
- setResult(RESULT_OK, replyIntent);
- finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement