This question already has an answer here:
I have two Activity, One is Mainactivity and another is Secondactivity. Secondactivity contains Webview that loads local HTML pages from assets folder.
Mainactivity contains buttons labeled as Button A and Button B when pressed would start Secondactivity. I would like to pass the string as URL from Mainactivity to Secondactivity which loads the A.html and B.html when Button A and Button B is pressed.
For now, I have following code in Mainactivity Class
Fragment firstFragment1 = new browser();
Bundle args1 = new Bundle();
args1.putString("url1", "file:///android_asset/diploma.html");
firstFragment1.setArguments(args1);
moveToFragment(firstFragment1);
break;
and on SecondActivity Class, I have following code
String url1 = getArguments().getString("url1");
myWebView=(WebView)rootView.findViewById(R.id.webview);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.getSettings().setLoadsImagesAutomatically(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.setInitialScale(1);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
WebSettings webSettings = myWebView.getSettings();
myWebView.loadUrl(url1);
return rootView;
}
Which work for Fragment flawlessly, but how do I make it work for Activity to activity??
In first activity you should put extra argument to intent like this:
Then in second activity you retrive argument like this:
If you're using activities, pass the url as a string and get it in the next activity.Like below code
In the webView,get it like this
Make one single common activity which load web url
for example:
Xml code :
Now you can load any url or html from whole app
From Activity :
From Fragment :
Webview load url
Webview load html from assets directory