Example Snippets Android Put Extra

// Snippet showing how to pass strings from as listview when starting a new intent //
/** MAIN ACTIVITY **/ 

protected void onCreate(Bundle savedInstanceState) {

	// Setup everything else we need in the on create for main activity
	... 


	// get list view from item from thing with the id listView in our gui
	ListView lv = (ListView) findViewById(R.id.listView);
	
	// Tell the list view to run this function when clicked 
	lv.setOnItemClickListener(new OnItemClickListener(){   
	    @Override
	    public void onItemClick(AdapterView<?>adapter,View v, int position){
	       listClicked(position);
	    }
	});


	//Other stuff that I want to put in the on create
	...

}

public void listClicked(int position) {

	// Get the list view
	ListView lv = (ListView) findViewById(R.id.listView);

	// make a string equal to the text at the position the user clicked 
	String selectedListItemName = String.valueOf(lv.getItemAtPosition(position));

	// Create an intent to start our other activity
	Intent i = new Intent(getApplicationContext(), OtherActivity.class);
	  
	// Put some extra data in that intent and mark it with the key "listData" so we can access it by that name later  
	i.putExtra("listData", selectedListItemName);  

	//Start the intent
	startActivity(i);

}

/** OTHER ACTIVITY **/
protected void onCreate(Bundle savedInstanceState) {

	// Setup everything else we need in the on create for other activity
	... 

	// Make a new string to hold the item we just passed
	// fill it with a default value in case no data was passed 
	String passedData = "default";

	// Get any extra data that was passed to this activity when we started it
	Bundle extras = getIntent().getExtras();

	// If this activity was passed extra data when it started
	// If the was some set passedData string to the string that was passed using the key "listData"
	if (extras != null)
		passedData = extras.getString("listData");

	// Now do stuff with the passedData string

	//Other stuff that I want to put in the on create
	...

}