Rutuja
Rutuja

Reputation: 1

How to pass Multiple information from one screen to another screen in android

I have a sign-up form, and I have to pass all info filled in that form to another screen. I know how to display if there is one field, but in sign-up form there are multiple fields. so I want to know how to display all the info.

Upvotes: 0

Views: 1553

Answers (3)

Yogendra
Yogendra

Reputation: 5260

To pass User data(multiple info) from one screen to another screen :

  1. Create a model for user with setter and getter method.
  2. make this class Serializable or Parcelable (Prefer) .
  3. Create object of user class and set all data using setter method.
  4. Pass this object from one activity to another by using putSerializable.

    Person mPerson = new Person();

    mPerson.setAge(25);  
    Intent mIntent = new Intent(Activity1.this, Activity2.class);  
    Bundle mBundle = new Bundle();  
    mBundle.putSerializable(SER_KEY,mPerson);  
    mIntent.putExtras(mBundle);  
    
    startActivity(mIntent); 
    
  5. And get this object from activity 2 in on create methode.

    Person mPerson = (Person)getIntent().getSerializableExtra(SER_KEY);

and SER_KEY will be same.

for more detail please go to this link:

http://www.easyinfogeek.com/2014/01/android-tutorial-two-methods-of-passing.html

I hope it will work for you.

Upvotes: 1

burmat
burmat

Reputation: 2548

If you are launching a new activity, just create a Bundle, add your values, and pass it into the new activity by attaching it to the Intent you are using:

/*
 * In your first Activity:
 */

String value = "something you want to pass along";
String anotherValue = "another something you would like to pass along";

Bundle bundle = new Bundle();
bundle.putString("value", value);
bundle.putString("another value", anotherValue);

// create your intent

intent.putExtra(bundle);
startActivity(intent);


/*
 * Then in your second activity:
 */

Bundle bundle = this.getIntent().getExtras();
String value = bundle.getString("value");
String anotherValue = bundle.getString("another value");

Upvotes: 3

Fahim
Fahim

Reputation: 12358

You can make use of bundle for passing values from one screen to other

Passing a Bundle on startActivity()?

Upvotes: 0

Related Questions