Tuesday, 26 June 2012

Passing a Bundle on Activity


1) Use the Bundle from the Intent:
Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);
 
2) Create a new Bundle
Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.extras.putString(key, value);
mIntent.putExtras(mBundle);
 
3) Use the putExtra() shortcut method of the Intent
Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value); 
 
 
Getting Value in naother activity
 
Bundle bundle = this.getIntent().getExtras();  
if(bundle !=null) {
  String strdata = bundle.getString("senddata");
}
 

1 comment: