Passing parameters from one Activity to another

Asked

Viewed 3,604 times

1

I need to pass the name of a product selected in a ListView to be presented in a EditText.

I am currently on the screen that the user informs the customer and then opens the screen of new order, on this screen I have a button to select a product of this ListView.

Problem: When I enter Activity from the list and select the product, it start in a new order screen restarting customer information and showing only the product name in the EditText.

How I avoid the new load update only the EditText?

  • I’m a little confused, I’m not sure what you’re up to.

2 answers

5

Good afternoon, maybe I was a little confused with your description, but I will try to answer for what I understood, to pass the information from one Activity to another just reuse the Bundle and go ahead of Activity in Activity.

example:

//código para obter o bundle da activity anterior
Bundle bundle = getIntent.getExtras();

//obter alguma informação do bundle
String nome = bundle.getString("nome");

//adiciona alguma informação no bundle
bundle.putInt("idCliente", idCliente);
bundle.putFloat("valorProduto", valorProduto);

//passa o bundle para a próxima activity
startActivity(suaIntent.putExtras(bundle));

and as for starting a new screen try using the startActivityForResult method instead of just startActivity to start the list. With this you return a result to the previous Activity. Here has a tutorial on how to return a result from an Activity.

  • So I had tested like this, only when I give a startActivity or even by the For result, it picks up my Activity again.

  • Look at my current code. ' Intent Intent = new Intent(Listproductosbd.this, Novopedidoactivity.class); // Used for passing parameter on Android better than staying // copying. Bundle parameter = new Bundle(); putString("nmProd", productSel = ((Textview) view).gettext() .toString(); // productSel = ((Textview) view). gettext(). toString(); Intent.putExtra("product", productSel.toString(); //startActivityForResult(Intent, SELECIONAR_PRODUTO); Finish();'

  • make the Activity for result on the order screen, it will call the product list and as soon as it is finished, it will return with the result as in the example you have in this question of Soen here

1

When you call the method finish(); Android removes the Activity of the pile and has no way to return to it. If it is not this post the classes for further understanding.

Browser other questions tagged

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