Send data from one Activity to another

Asked

Viewed 16 times

0

Good afternoon, I’ve been trying to pass an Edittext from one Activity to another, but I’m not getting it.

Activity A.

listaViewLivros.setOnItemClickListener(new AdapterView.OnItemClickListener()
 {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                view.setSelected(true);
                Intent intent = new Intent(AddActivity.this, FinalActivity.class);
                intent.putExtra("ChaveTitulo", edtTitulo.getText().toString());
                startActivity(intent);
                finish();
            }

Activity B.

protected void onCreate(Bundle savedInstanceState) 
{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_final);
        saidaTitulo = (EditText) findViewById(R.id.saidaTitulo);
        String novoTitulo = getIntent().getStringExtra("ChaveTitulo");
        saidaTitulo.setText(novoTitulo);
       
    }

I can not at any time pass the information inside the "outTitulo".

1 answer

0

I have here a small example of a project of mine:

Activity A

 Intent intent = new Intent(MainActivity.this, SensorActivity.class);
                                intent.putExtra("name", name);
                                MainActivity.this.startActivity(intent);
                                finish();

Activity B

 Intent intent = getIntent();
        String name = intent.getStringExtra("name");

        tvWelcomeMsg = findViewById(R.id.tvWelcomeMsg);
        
        String message = "Welcome " + name;
        tvWelcomeMsg.setText(message);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.