Created
June 5, 2011 03:33
-
-
Save emoa2l/1008617 to your computer and use it in GitHub Desktop.
Android: Create a new window(activity) and pass parameters to it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Activity1 extends Activity { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
setContentView(R.layout.main); | |
// in the calling activity define a bundle that can contain | |
// some number of strings | |
Bundle bundle = new Bundle(); | |
bundle.putString("paramter", "value"); | |
// create the intent to launch the new activity | |
Intent i = new Intent(Activity1.this, Activity2.class); | |
// attach the bundle to the intent and then start it | |
i.putExtras(bundle); | |
startActivityForResult(i,0); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Activity2 extends Activity { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.showdefinition); | |
// initialize a bundle and set it to the current intents bundle | |
Bundle bundle = this.getIntent().getExtras(); | |
TextView tv = (TextView) findViewById(R.id.<viewId>); | |
// you can now reference any strings defined in the bundle in | |
// the calling activity | |
tv.setText(bundle.getString("paramter")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment