How to pass data from one Activity to another

Asked

Viewed 16,877 times

1

I am creating an app for pizzerias in my city and would like to know if it is possible to send data of a Listactivity that contains pizza names for another Listactivity named favorites, so that pizzas can be added to the favorites list.

How can I do that?

  • The editing was done wrong. Because the essential part was removed where I said it is from one listview to another, but in different activitys.

  • http://answall.com/questions/27175/enviar-um-arraylist-de-objetos-para-uma-activity

  • 1

    Rony, if you do not agree with any editing made in your question you can reverse it. Click on the word editada, which lies above the "flair" who edited it. Then, next to the version number you want to return to, click on reverter. I suggest you read the section how to ask and you’ll understand why the editing was done.

2 answers

2

There are some ways to "chat" between Activities, to simply send some information to other Activities, you can use the Bundle in this way:

                    Bundle bundle = new Bundle();
                    bundle.putString("nomeCliente", cliente.getNome(position));
                    Intent intent = new Intent(context, MinhaOutraActivity.class);
                    intent.putExtras(bundle);
                    startActivity(intent);

Now, if you need to create a bookmark system, you need to save this information in the Database or in a preferred file. You can consult how to do this here:

How to use Sharedpreferences in Android to store, fetch and Edit values

Sqlite on Android, Understanding and Using

  • Opa really liked the answer, this code is placed inside the Activity (pizzas) that I will pass to the other correct? I have several items on the list, I would like that when the user held the listview item appeared an option to add a pizza chosen for the other Activity, I can do using this code?

1

Only one correction is putExtra as below:

     Bundle bundle = new Bundle();
                bundle.putString("nomeCliente", cliente.getNome(position));
                Intent intent = new Intent(context, MinhaOutraActivity.class);
                intent.putExtra(bundle);
                startActivity(intent);
  • Opa really liked the answer, this code is placed inside the Activity (pizzas) that I will pass to the other correct? I have several items on the list, I would like that when the user held the listview item appeared an option to add a pizza chosen for the other Activity, I can do using this code?

  • It is even necessary to create a database?

Browser other questions tagged

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