Reputation: 1564
I am trying to get information from Activity
B, into Activity
A, the problem is that the value that i am getting is returning null
for some reason. My code see's how many times you click on the Button
and returns the value into my first Activity
, at least thats what it is suppose to do. If sombody see's my mistake please tell me, i have class in 5 hours :\
returned.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Next.this, Hw3Activity.class);
intent.putExtra("text", counted.getText().toString());
startActivity(intent);
/*Next is the current activity, Counted is the name of my text box*/
}
});
click.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
}
This is the Activity
i want the information transferred to.
Button change;
TextView text;
int number;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
change = (Button) findViewById(R.id.change);
text = (TextView) findViewById(R.id.count);
String s1 = getIntent().getStringExtra("Textview01");
text.setText("You clicked the button " + s1 + " times.");
change.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Next.class);
startActivityForResult(intent, 0);
/*this button is for going to the 2nd activity,not my problem currently*/
}
});
}
}
Upvotes: 2
Views: 187
Reputation: 123
try
String s1 = getIntent().getStringExtra("text");
Because You are sending string value tag as "text"
.
Upvotes: 0
Reputation: 4437
In the Activity
where you want the info, there is an error. You need to put "text"
instead "Textview01"
.
You can use the following with error control.
Bundle extras = getIntent().getExtras();
if( extras != null){
String text = extras.getString("text");
}
Upvotes: 2
Reputation: 68187
here's what you are doing wrong:
String s1 = getIntent().getStringExtra("Textview01");
i believe it should be:
String s1 = getIntent().getStringExtra("text");
Upvotes: 2