I’ve got two classes. Class1 and Class2 – Both extend Activity.
Class1 Launches on the program launch and when you click a button it’s meant to slide to Class2 – this works fine.
However Class2 has a TextView which I want to change the text of depending on which button is clicked – but I can’t for the life of me work out how to do it
I’m using startActivity(Class1.this,Class2.class); to slide across which obviously creates a new instances of Class2
I’ve also tried creating an instance of Class2 and then calling startActivity(Class1.this,myVar.getClass());
but the result is the same, any ideas how I call Class2.someMethod(); so that it effects the newly displayed Class2 instance? or am I going about this the wrong way?
Thanks in advance!
No, you are not, as that will not compile. You are probably using:
That won’t compile either. Here is the documentation for
startActivity().You don’t.
If you want to pass data to the new
Activity— and the data is simple, like you might put in parameters of a URL in a Web app — then package it as anIntentextra:Then, in
Class2, inonCreate(), you can callgetIntent().getStringExtra("some key")to retrieve the data.