How do I pass a value from one class to another.
eg
Class one
public String aButton(View view) {
startActivity(new Intent(this, ContentHolder.class));
this.choice = "kick_boxing.txt";
return choice;
}
This causes an activity to open. This method is called when the user clicks on the relevant button.
In this newly opened activity, I want to set the String to choice made by clicking one of several buttons. Since java doesn’t do multiple extending, I can’t extend the activity and this class, which I think I need in order to use inheritance.
So, what can I do to pass the choice from class A to Class B?
EDIT
public String aButton(View view) {
Intent i = new Intent(getApplicationContext(), ContentHolder.class);
i.putExtra("choice", choice);
startActivity(new Intent(this, ContentHolder.class));
this.choice = "kick_boxing.txt";
return choice;
}
and in the other class, just in the onCreate (I think of these as main methods?)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context m_Context = getApplicationContext();
TextView textview = new TextView(this);
textview.setText("This is the content view");
setContentView(textview);
Bundle extras = getIntent().getExtras();
if(extras !=null) {
String value = extras.getString(key);
}
InputStream input;
try {
input = m_Context.getAssets().open(fileName);
key cannot be resolved.
Easy like this..
in your current activity, create an intent
startActivity(i);
then in the other activity, retrieve those values.