Android:在其他活动上加载url';s网络视图
正如标题所说 例如: 我有MainActivity和main.xml main.xml有WebView“@+id/WebView1” 打开SecondActivity后,我希望它在MainActivity的webview上加载URLAndroid:在其他活动上加载url';s网络视图,android,view,android-activity,webview,Android,View,Android Activity,Webview,正如标题所说 例如: 我有MainActivity和main.xml main.xml有WebView“@+id/WebView1” 打开SecondActivity后,我希望它在MainActivity的webview上加载URL 有什么解决方案吗?将您的url放入附加内容 myIntet.putExtra("url", "www.abc.com"); 在第二个活动中访问它 String url = getIntent().getExtras().getString("url"); 在we
有什么解决方案吗?将您的url放入附加内容
myIntet.putExtra("url", "www.abc.com");
在第二个活动中访问它
String url = getIntent().getExtras().getString("url");
在webview中呈现url
WebView webView = (WebView)findViewById(R.id.webview);
webView.loadUrl(url);
在MainActivity.java中
WebView webView;
static WebView sWebView; // because we will use in static method
将它们放入oncreate方法中
webView = (WebView )findViewById(webview);
sWebView= webView ;
创建下面的方法
// it is static because we will call it from second actvity
static loadUrl (String Url){
sWebView.webloadUrl(url);
}
在创建方法的第二个活动中
MainActivity.loadUrl("your URL"); // because load url is a statci method, you can call the it from other class.
实现自定义侦听器(接口)。“findViewById(R.id.WebView1);”提供空值。在应用程序生命周期的哪个点尝试执行此操作?应在activity的onCreate方法中尝试此操作。确定后,找到WebView,并成功加载URL。但是SecondActivity的onCreate仍然会打开一个新窗口(删除super.onCreate()会给出一个错误)哈哈,你很有趣:P但是你也很好。我自己解决了这个问题,在打开请求的URL后执行这个.finish()。现在一切都很好。谢谢