0

total newby to developing, but I've run through the developer tutorial on the android developer site. I don't know how to pass an integer from my main activity to a new activity. I have a series of questions that require integer inputs (works well), then those integers are manipulated to give a single integer output (works well also).

However, I now want to take said resultant integer and display nicely in a new activity after a button is clicked. The tutorial I worked through only used getString and getInt does not exist. For an absolute novice, I'm wandering in the dark.

Thanks in advance for any help.

1 Answers1

1

Use Bundle:

Intent i=new Intent(NewActivity.class)
Bundle b=new Bundle();
b.putString("name","value");
i.putExtras(b);
startActivity(i);

Then in NewActivity use:

Bundle e=getIntent().getExtras();

String value =e.getString("name");

Using this you can send values from one activity to another.

EduardoSaverin
  • 545
  • 4
  • 19
  • Sorry for the possibly stupid question, but won't that send a String? I have an Integer calculated by a ridiculous if-else tree. I need to take that resultant int to a new activity. – user2515301 Jun 25 '13 at 02:59
  • You can convert that string to an integer later – EduardoSaverin Jun 25 '13 at 03:15
  • Thanks for the help John. So far so good. Only issue I'm having now is that in the NewActivity, I'm getting "name" is not a field. – user2515301 Jun 25 '13 at 07:06
  • Have you successfully sent the value from the first activity,and parsed it to integer.. – EduardoSaverin Jun 25 '13 at 07:13
  • After reading your last post, in the NewActivity, I only need to display it, so String will be fine. All the manipulation/computation is done in MainActivity, so it should work. Like I said, this is all pretty new to me. – user2515301 Jun 25 '13 at 07:26