How to pass data between Activities [duplicate]

0

I have a code that transforms getText into string and would like to pass this string to another activity in a simple way, but not an activity coming soon after that.

My code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    editTextEmail = (EditText) findViewById(R.id.email);
    editTextPassword = (EditText) findViewById(R.id.password);
    buttonSignIn = (Button) findViewById(R.id.email_sign_in_button);
    cadastro_button  = (Button) findViewById(R.id.cadastro_button);


    progressDialog = new ProgressDialog(this);

    buttonSignIn.setOnClickListener(this);
    cadastro_button.setOnClickListener(this);


    buttonSignIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String email = editTextEmail.getText().toString();
            String password = editTextPassword.getText().toString();

            attemptLogin(email, password);

        }
    });
}
    
asked by anonymous 18.05.2017 / 20:18

1 answer

2

You should use Intent for this, following example:

1st Activity:

Intent i = new Intent(Activity.this, NewActivity.class);
i.putExtra("key", value);
startActivity(i);

2nd Activity:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("key");
}
    
18.05.2017 / 20:21