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
package com.example.wenchen.helloworld;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class NextActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_next );

    final TextView tvView = (TextView) findViewById( R.id.tvView );
    Intent intent = getIntent( );
    String name = intent.getStringExtra( "name" );
    tvView.setText( "Welcome, " + name );
    final Button button = (Button) findViewById( R.id.home );
    button.setOnClickListener(
      new View.OnClickListener( ) {
        public void onClick( View v ) {
          Intent i = new Intent( NextActivity.this, MainActivity.class );
          startActivity( i );
        }
      }
    );
  }

  @Override
  public boolean onCreateOptionsMenu( Menu menu ) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater( ).inflate( R.menu.menu_next, menu );
    return true;
  }

  @Override
  public boolean onOptionsItemSelected( MenuItem item ) {
    // Handle action bar item clicks here.  The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId( );

    // noinspection SimplifiableIfStatement
    if ( id == R.id.action_settings ) {
      return true;
    }
    else if ( id == R.id.home ) {
      Intent i = new Intent( NextActivity.this, MainActivity.class );
      startActivity( i );
    }
    return super.onOptionsItemSelected( item );
  }
}




      Let’s come back soon before the heavens open.