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 based on your selection from submenu. You gonna share variable myValue

From Activity1
Intent intent = new Intent(this,myActivity2.class);
Bundle bundle = new Bundle();
bundle.putString(“myValue“, myValue);
intent.putExtras(bundle);
navigation.this.startActivity(intent);
In Activity2
Bundle bundle = getIntent().getExtras();
act2MyValue= bundle.getString(“myValue“);
//Now is your application powered to share variables between two different activities.

0 comments:

Post a Comment