Java Source Code (Cont.)

import android.widget.TextView;
Displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing; see EditText for a subclass that configures the text view for editing.

final TextView tvView = (TextView) findViewById( R.id.tvView );
The method findViewById of the class View looks for a child view with the given id such as R.id.tvView.

Intent intent = getIntent( );
Create an intent, which is an abstract description of an operation to be performed. The intent is from the MainActivity using startActivity to launch the current activity.

String name = intent.getStringExtra( "name" );
Retrieve extended data from the intent, where the "name" is the name of the desired item.

tvView.setText( "Welcome, " + name );
Set the text that this TextView is to display and also sets whether it is stored in a styleable/spannable buffer and whether it is editable.
HelloWorld/app/src/main/java/com/example/wenchen/helloworld/NextActivity.java
01package com.example.wenchen.helloworld;
02 
03import android.app.Activity;
04import android.content.Intent;
05import android.os.Bundle;
06import android.view.Menu;
07import android.view.MenuItem;
08import android.view.View;
09import android.widget.Button;
10import android.widget.TextView;
11 
12public class NextActivity extends Activity {
13  /** Called when the activity is first created. */
14  @Override
15  public void onCreate( Bundle savedInstanceState ) {
16    super.onCreate( savedInstanceState );
17    setContentView( R.layout.activity_next );
18 
19    final TextView tvView = (TextView) findViewById( R.id.tvView );
20    Intent intent = getIntent( );
21    String name = intent.getStringExtra( "name" );
22    tvView.setText( "Welcome, " + name );
23    final Button button = (Button) findViewById( R.id.home );
24    button.setOnClickListener(
25      new View.OnClickListener( ) {
26        public void onClick( View v ) {
27          Intent i = new Intent( NextActivity.this, MainActivity.class );
28          startActivity( i );
29        }
30      }
31    );
32  }
33 
34  @Override
35  public boolean onCreateOptionsMenu( Menu menu ) {
36    // Inflate the menu; this adds items to the action bar if it is present.
37    getMenuInflater( ).inflate( R.menu.menu_next, menu );
38    return true;
39  }
40 
41  @Override
42  public boolean onOptionsItemSelected( MenuItem item ) {
43    // Handle action bar item clicks here. The action bar will
44    // automatically handle clicks on the Home/Up button, so long
45    // as you specify a parent activity in AndroidManifest.xml.
46    int id = item.getItemId( );
47 
48    // noinspection SimplifiableIfStatement
49    if ( id == R.id.action_settings ) {
50      return true;
51    }
52    else if ( id == R.id.home ) {
53      Intent i = new Intent( NextActivity.this, MainActivity.class );
54      startActivity( i );
55    }
56    return super.onOptionsItemSelected( item );
57  }
58}