1

I am building an App that leverages the Google Map and Places API. I do not want to use the Places Info Window but I want to open a new Activity and populate the Layout with data when the Place icon is selected. I am able to pass the telephone information and other data using Intent and Intent-Extra. However I am having difficulty passing the URL or Website of the Location even though I don't get an error, the layout text view field just returns blank. My code is as below.

From the sending Activity             



String phonenum=mPlace.getPhoneNumber();
intent.putExtra("Phone Number: ", phonenum);
Uri Web = mPlace.getWebsiteUri();
intent.putExtra("Web: ", Web);

In the Receiving Activity my Code is as follows

Bundle bundle = getIntent().getExtras();
String phonenum = bundle.getString("Phone Number: ");
String Web = bundle.getString("Web: ");        
TextView Txtview3 = (TextView) findViewById(R.id.telephone);
Txtview3.setText(phonenum);
TextView web = (TextView) findViewById(R.id.url7)                 
web.setText(Web);

As I mentioned the phone number code works fine, but I don’t know what I am missing with the URL code. I have checked a number of answers and found no solution. Any ideas would be appreciated

Noruwa
  • 93
  • 9
  • 1
    possible duplicate of https://stackoverflow.com/a/8017425/7824493 – Paresh Rajput Nov 30 '18 at 13:53
  • Many thanks Paresh for pointing me in the right direction. I converted the URL to Sting, passed it via the intent as String and inserted into the textview still as String and include the autolink in my XML file as below and it worked – Noruwa Nov 30 '18 at 14:09
  • Uri Web = mPlace.getWebsiteUri(); intent.putExtra("Web: ", Web.toString()); – Noruwa Nov 30 '18 at 14:10
  • String Web =bundle.getString("Web: "); TextView web = (TextView) findViewById(R.id.url7); web.setText(Web); – Noruwa Nov 30 '18 at 14:11
  • If you want to place a horizontal rule in your text, you need a blank line between the last line of text and your hyphens (---), otherwise you get that horrible bolded text at the top of your question. – keag Nov 30 '18 at 15:15

1 Answers1

1

Uri class implements parcelable interface, so you should:

In the parent activity:

Intent intent = new Intent(this, SecondActivity.class);
Uri uri = mPlace.getWebsiteUri();
intent.putExtra("web_uri_identifier", uri);
startActivity(intent);

In the destination activity:

Uri uri = getIntent().getExtras().getParcelable("web_uri_identifier");

Remember to start your variable names with a lowercase letter in order to distinguish variables from classes

Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64