User:Workbase/sandbox

=
= MainActivity

=
= package com.example.sendvaluetootherscreen;

import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.EditText;

public class MainActivity extends Activity { public final static String NAME_MESSAGE = "com.example.SendValueToOtherScreen.MESSAGE"; public final static String NAME_MESSAGE2 = "com.example.SendValueToOtherScreen.MESSAGE2"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }

/** Called when the user clicks the Submit button */ public void sendName(View view) {      	Intent intent = new Intent(this, DisplayMainActivity.class); Bundle extras= new Bundle; // Do something in response to button EditText editText1 = (EditText) findViewById(R.id.editText1); String message1 = editText1.getText.toString; extras.putString(NAME_MESSAGE, message1); EditText editText2 = (EditText) findViewById(R.id.editText2); String message2 = editText2.getText.toString; extras.putString(NAME_MESSAGE2, message2); intent.putExtras(extras); startActivity(intent); }    @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater.inflate(R.menu.main, menu); return true; } }

=
====== DisplayMainActivity

=
======

package com.example.sendvaluetootherscreen;

import android.annotation.TargetApi; import android.app.Activity; import android.os.Build; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView;

public class DisplayMainActivity extends Activity {

//@SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Intent intent = getIntent; Bundle bundle= getIntent.getExtras; String message = bundle.getString(MainActivity.NAME_MESSAGE); String message2 = bundle.getString(MainActivity.NAME_MESSAGE2); // Create the text view TextView textView = new TextView(this); textView.setTextSize(40); textView.setText("Hello and welcome "+ message+" "+message2); // Set the text view as the activity layout setContentView(textView); }	/**	 * Set up the {@link android.app.ActionBar}, if the API is available. */	@SuppressWarnings("unused") @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setupActionBar { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getActionBar.setDisplayHomeAsUpEnabled(true); }	}

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

@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: //			// http://developer.android.com/design/patterns/navigation.html#up-vs-back //			NavUtils.navigateUpFromSameTask(this); return true; }		return super.onOptionsItemSelected(item); }

}