1
I have a ActivityA
, contains a ListView
and a botão
, and I have a ActivityB
containing two EditText
and a button.
When do I start app
begins in the ActivityA
with empty list, when pressing the button executes the following code
Intent it = new Intent(this, ActivityB.class);
startActivity(it);
Now I’m in the ActivityB
fill in the EditTex
and press the button that executes the following code
String texto = editTexto.getText().toString();
double numero = Double.parseDouble(editnumero.getText().toString());
Intent it = new Intent(this, ActivityA.class);
it.putExtra("texto", texto);
it.putExtra("numero", numero);
startActivity(it);
So am I in the ActivityA
, within the onCreate
follows the code
Intent it = getIntent();
texto = it.getStringExtra("texto");
numero = it.getDoubleExtra("numero", -1);
if(texto != null)
//List<Carro> carro = new ArrayLis<Carro>(); variável global
carro.add( new Desejo(texto,numero));
carroAdapter = new ArrayAdapter<Carro>(this, android.R.layout.simple_list_item_1,carro );
listaCarro.setAdapter(carroAdapter);
}
Okay, it works, but when I click the button again I go to ActivityB
, I type the values and I click the button, I go to ActivityA
. what had been added earlier was gone and the last data was triggered in the list.
But I noticed he opened another window.
How to solve this window problem and whether the value was added to the list even if it opened in another window was to have the full list?
In the way it is formulated, the question is duplicated. However, given what you want to do better would be to use
startActivityForResult()
to launch Activity B. See this reply and in the documentation How to get results from an activity– ramaral
@ramaral when you write Launch Activity B, you mean go A to B, or B to A
– Vale
Go from A to B.
– ramaral