Android using Bundle for sharing variables
Sharing variables between Activities is quite important point during development time of your Application. This Example suppose Activity1 from where you run up other Activity2 . You gonna share variable myValue.
From Activity1
Intent intent = new Intent(myActivity1.this,myActivity2.class);
Bundle bundle = new Bundle();
bundle.putString(“myValue“, myValue);
intent.putExtras(bundle);
startActivity(intent);
OR
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtra("myValue",AnyValue);
startActivity(intent);
In Activity2
Bundle bundle = getIntent().getExtras();
String value= bundle.getString(“myValue“);
OR
Intent intent=getIntent();
Bundle bundle=intent.getExtras();
String value= bundle.getString(“myValue“);
Now is your application powered to share variables between two different activities.
Sharing variables between Activities is quite important point during development time of your Application. This Example suppose Activity1 from where you run up other Activity2 . You gonna share variable myValue.
From Activity1
Intent intent = new Intent(myActivity1.this,myActivity2.class);
Bundle bundle = new Bundle();
bundle.putString(“myValue“, myValue);
intent.putExtras(bundle);
startActivity(intent);
OR
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtra("myValue",AnyValue);
startActivity(intent);
In Activity2
Bundle bundle = getIntent().getExtras();
String value= bundle.getString(“myValue“);
OR
Intent intent=getIntent();
Bundle bundle=intent.getExtras();
String value= bundle.getString(“myValue“);
Now is your application powered to share variables between two different activities.
No comments :
Post a Comment