Java Source Code (Cont.)

package com.example.wenchen.helloworld;
The package reference is com.example.wenchen.helloworld.

import android.app.Activity;
An activity is a single application entity that is used to perform actions. An application may have many separate activities, but the user interacts with them one at a time. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View).

import android.content.Intent;
An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities.

import android.os.Bundle;
It is a mapping from String values to various Parcelable types. Android use Parcel, which is a container for a message (data and object references), to pass data through services.

import android.view.View;
This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.).

import android.widget.Button;
It represents a push-button widget. Push-buttons can be pressed, or clicked, by the user to perform an action.
HelloWorld/app/src/main/java/com/example/wenchen/helloworld/MainActivity.java
package com.example.wenchen.helloworld;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_main );
    final EditText name = (EditText) findViewById( R.id.name );
    final Button button = (Button)   findViewById( R.id.next );
    button.setOnClickListener(
      new View.OnClickListener( ) {
        public void onClick( View v ) {
          /** Here i calls a new screen. **/
          Intent i = new Intent( MainActivity.this, NextActivity.class );
          i.putExtra( "name", name.getText( ).toString( ) );
          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_main, 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.next ) {
      Intent i = new Intent( MainActivity.this, NextActivity.class );
      startActivity( i );
    }
    return super.onOptionsItemSelected( item );
  }
}




      Kevin says he was completely in the dark    
      about the CEO’s plans to sell the company.