Android Example Passing Variables Between Activities using Intent

Here is an example of passing variables between activities using Intent. It is easy to add extra inside an intent but unless you do it a lot then you may after reference an example.

Activity Creating the Intent and Starting the other Activity  (Activity1):

   Intent next = new Intent(EditSchedule.this, ConfirmSchedule.class);
   
   next.putExtra("duration",durationSelection); 
   next.putExtra("frequency",frequencySelection); 
   next.putExtra("taxYear",taxYearSelection);
   next.putExtra("amount", amountContribute.getText().toString());
   next.putExtra("startDate",date); 
   EditSchedule.this.startActivity(next);

Grabbing the variables in the next Activity from Activity1

public class Activity2 extends Activity{

	String duration ="", frequency = "", taxYear = "", amount = "", startDate = "";

	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.contribution_confirm_schedule);

	    Bundle b = getIntent().getExtras();  

            /**
            * also you can do:  
            * duration = getIntent().getExtras().getString("duration");
            **/

            if(b != null){  // may not be needed in your case
               duration = b.getString("duration");
	       frequency = b.getString("frequency");
               taxYear = b.getString("taxYear");
	       amount = b.getString("amount");
               startDate = b.getString("startDate");
            }

            /**
            * also you can do (not tested):  
            * ((TextView) findViewById(R.id.duration)).setText(getIntent().getExtras().getString("duration"));
            **/

	    ((TextView) findViewById(R.id.start_date)).setText(startDate);
	    ((TextView) findViewById(R.id.end_date)).setText("??");
	    ((TextView) findViewById(R.id.frequency)).setText(frequency);
	    ((TextView) findViewById(R.id.amount_contribute)).setText(amount);
	    ((TextView) findViewById(R.id.bank_name_confirmed)).setText(DD.bankName);
	    ((TextView) findViewById(R.id.account_number_confirmed)).setText(DD.accountNumber);
	    ((TextView) findViewById(R.id.routing_number_confirmed)).setText(DD.routingNumber);	    
	  }
       }

Graveyard Database Logo

Has everything you want to know about grave yards. Plus has many celebrites and world leaders graves. Pssst it is my other site

Google + Profile
Check out Android Photo Mapping, its a app/site I been working on
  • wholesale nfl jerseys
  • wholesale nfl jerseys china
  • wholesale sports jerseys