0

I currently have a code for a map that would take information from two edittexts and would display it as direction on a map (From and To). I'm using google autocomplete in another activity (activity 1). I would like to send the data from the autocomplete textviews in activity 1 to the edittexts in the next activity (map activity). How can I do this?

Thank you in advance.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Joe
  • 5
  • 3

1 Answers1

0

You can use Intent class.

In Activity1, just before call startActivity put the data in a Intent

Intent i = new Intent(Activity1.this, Activity2.class);
i.putExtra("KeyFrom", fromText );
i.putExtra("KeyTo", toText );
startActivity(i);

In Activity2 you have to get the data from the Intent in the onCreate method:

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layoutActivity2);
    Bundle bundle = getIntent().getExtras();

    if(bundle.getString("KeyFrom")!= null)
    {
      String textFrom = bundle.getString("KeyFrom");
    }
    if(bundle.getString("KeyTo")!= null)
    {
      String textFrom = bundle.getString("KeyTo");
    }

}

Hope it helps!

jos
  • 1,070
  • 12
  • 22
  • Sorry I'm kind of a noobie. How would you introduce the textFrom and textTo variables in the second activity – Joe Oct 09 '16 at 17:38
  • Hi, if I don't know if I understood you correctly, but you pass the values of the variables and you have to declare the variables textFrom and textTo in the second activity. You can declare them as global if you want to access in whole activity. – jos Oct 09 '16 at 17:55