Skip to content Skip to sidebar Skip to footer

Using Integers, Strings Etc In Other Activities

I've got two Activities. In one I calculate some things and therefore I have some Integers and also some Strings stored. So now I would like to use these Stings and Integers in my

Solution 1:

You gotta pass them to your second activity.

When you create Intent to start activity

Intent i = new Intent(FirstActivity.this, SecondActivity.class);

do extra step like this

i.putExtra("integer", myInteger); //where myInteger is integer you have in first Activity
i.putExtra("string", myString); //where myString is String you have in first Activity

startActivity(i);

and now in second Activity to access those values use following code

int in = this.getIntent().getExtras().getInt("integer");
String str = this.getIntent().getExtras().getString("string");

as simple as that


Post a Comment for "Using Integers, Strings Etc In Other Activities"