我无法使用从前一个Activity传递来的链接加载页面。
以下是代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_webpage);
webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
/*Bundle b = getIntent().getExtras();
String url = b.getString(DeviceDetails.URL_KEY);*/
String url = getIntent().getStringExtra(DeviceDetails.URL_KEY);
//String url = "http://google.pl/nexus/4";
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl(url);
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
当我使用String url="http://google.pl/nexus/4"时,一切似乎都很好。我非常确定我的活动从getIntent中获取了url,因为我进行了调试。
更新1:
String inputUrl = detUrlEditText.getText().toString();
Intent intent = new Intent(DeviceDetails.this, ShowWebPageActivity.class);
Bundle extras = new Bundle();
extras.putString(URL_KEY, inputUrl);
intent.putExtras(extras);
startActivity(intent);
上一个活动。我已经调试过了,所以保证可以传递url。而且toast也会在ShowWebPageActivity
中显示传递的url。
Intent
上的Extra
,这是与Bundle
不同的概念。 - FoamyGuy