Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Michael Mealy
13,247 PointsOpening a Webpage with Android
Can someone help me with Task three of this code challenge please.
The Task is : Now get the URI that you passed in as the data for the Intent. Convert it to a String URL and store it in the 'mUrl' member variable.
my code so far is:
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
public class WebViewActivity extends Activity {
protected String mUrl;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
WebView webView = (WebView) findViewById(R.id.webView1);
Intent intent = getIntent();
Uri blogUri = intent.getData();
WebView webView = (WebView) findViewById (R.id.webView1);
webView.loadUrl(blogUri.toString());
}
}
5 Answers
Ernest Grzybowski
Treehouse Project ReviewerHey Michael,
I believe you were at:
Android Development > Build a Blog Reader Android App > Using Intents to Display and Share Posts > Opening a Webpage Within the App
The challenge that comes after this video is a little different from the video. (Which is good... it get's you to think)
You need to read the question they give you carefully.
"Now get the URI that you passed in as the data for the Intent. Convert it to a String URL and store it in the 'mUrl' member variable."
They never tell you to create a new variable (which you do), but actually to place the data as a string into the mUrl variable.
This code passes challenge number 3.
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
public class WebViewActivity extends Activity {
protected String mUrl;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
WebView webView = (WebView) findViewById(R.id.webView1);
// Add code here!
Intent intent = getIntent();
mUrl = intent.getData().toString();
}
}
Additionally, in challenge three it never asks you to declare a webView, and it never asks you to load the Url. Look at the code you pasted in your question. You have this typed twice:
WebView webView = (WebView) findViewById (R.id.webView1);
Which is not required at all. Especially in part three.
Keep coding!
Ernest Grzybowski
Treehouse Project ReviewerCan you specify exactly which lesson this is?
Example:
Android Development > Build a Blog Reader Android App > Using Intents to Display and Share Posts > Opening a Webpage in the Browser
Ben Jakuben
Treehouse Teacher@Ernest, ! Thanks for answering this!
Michael Mealy
13,247 PointsThanks heaps for that
James Barnett
39,199 PointsA link to the code challenge that is giving you trouble is much more helpful than, writing out which video you are on.