Articles‎ > ‎Android Articles‎ > ‎

Passing Arguments One Activity to Another Activity In Android

posted Dec 25, 2010, 1:48 AM by Thiyagaraaj M   [ updated Aug 20, 2011, 4:41 AM ]

Assume:

Passing Argument A Activity to B another activity

Using Methods:

For A Class

getIntent().getStringExtra(....);
Toast.makeText(...).show();

For B Class

String NullString = "null";
new Intent(...);
i.putExtra(...);
startActivity(..);

Example:

For A Class Code:

String Example = "Hai";
Intent intent = new Intent(A.this, B.class);
intent.putExtra("id",Example.toString());
startActivity(intent);

For B Class Code:

String Id = getIntent().getStringExtra("id");
Toast.makeText(B.this, "Show :"+Id.toString(), Toast.LENGTH_SHORT).show();