-1

How do i get all the user input fields from signupActivity which is currently taking email, passwords and rest of the fields as input from the user and use it in finalactivity.

I already have made the xml layout and wonder how can i display all these fields to a newer activity which is called when signup button is pressed.

My SignupActivity.java:-

public class SignupActivity extends AppCompatActivity {    
    @Bind(R.id.input_name) EditText _nameText;
    @Bind(R.id.input_email) EditText _emailText;
    @Bind(R.id.input_password) EditText _passwordText;
    @Bind(R.id.btn_signup) Button _signupButton;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signing);
        ButterKnife.bind(this);
        _signupButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                  signup();
            }
        });
    }
    public void signup(){
        //call the finalactivity and do the 
    }
}

And now finally the signup() function should call the activity finalActivity and print the info. Maybe like this- For eg in the finalactivity i want to display-

Your name is :"name here"
And your email is :"email here"

My question is different from How do I pass data between Activities in Android application? as i want to pass multiple variables (~50) and obviously dont want to create 50 Intents.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Rishav
  • 3,818
  • 1
  • 31
  • 49
  • 2
    @SatanPandeya That helped but i need to pass multiple variables not just a single one. Do I have to create new Intents For every new variable i want to pass? – Rishav Jun 04 '17 at 06:26
  • 1
    https://stackoverflow.com/questions/13601883/how-to-pass-arraylist-of-objects-from-one-to-another-activity-using-intent-in-an This is what u r lokin 4. –  Jun 04 '17 at 06:43

3 Answers3

2

One way to solve this problem is using Intent.

pass the required data from SignUp Activity to finalActivity using Intent

public void signup(){
    Intent intent  = new Intent(SignUp.this,finalactivity.class );
    intent.putExtra("name", name);//name you get from EditText
    intent.putExtra("email", email);//emailyou get from EditText
    startActivity( intent );  
}

In finalactivity, in OnCreate() method do this

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.final_activity);

    name=(EditText) findViewById(R.id.editText1);
    email=(EditText) findViewById(R.id.editText2);

    String name_v=getIntent().getStringExtra("name");
    String email_v=getIntent().getStringExtra("email");
    name.setText(name_v);
    pass.setText(email_v);


}

Hope this helps

Rehan Shikkalgar
  • 1,029
  • 8
  • 16
  • Well thanks a lot but is there a more convenient way? I mean do i have to create a new intent every time? Say i need to pass 100 variables .... Something like an array-intent stuff??? – Rishav Jun 04 '17 at 06:29
  • yeah you can pass arraylist through Intent – Rehan Shikkalgar Jun 04 '17 at 06:33
  • https://stackoverflow.com/questions/13601883/how-to-pass-arraylist-of-objects-from-one-to-another-activity-using-intent-in-an look into this – Rehan Shikkalgar Jun 04 '17 at 06:33
  • Well it did it. Thanks a lot. Pls update your answer so that others can follow. Marking it accepted now. – Rishav Jun 04 '17 at 06:39
0

In your current Activity, pass the result via Intent:

Intent i = new Intent(FirstActivity.this,SecondActivity.class);
i.putExtra("NAME_KEY", "NAME_VALUE");
i.putExtra("EMAIL_KEY", "EMAIL_VALUE");
i.putExtra("PASSWORD_KEY", "PASSWORD_VALUE");
startActivity(i);

Retrieve the result from another Activity:

Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String name = extras.getString("NAME_KEY");
        String email = extras.getString("EMAIL_KEY");
        String password = extras.getString("PASSWORD_KEY");
    }
Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
0
ArrayList<Object> object = new ArrayList<Object>();
Intent intent = new Intent(Current.class, Transfer.class);
Bundle args = new Bundle();
args.putSerializable("ARRAYLIST",(Serializable)object);
intent.putExtra("BUNDLE",args);
startActivity(intent);


Intent intent = getIntent();
Bundle args = intent.getBundleExtra("BUNDLE");
ArrayList<Object> object = (ArrayList<Object>) args.getSerializable("ARRAYLIST");

This would do probably. How to pass ArrayList of Objects from one to another activity using Intent in android? --source