Hello!
In MainActivity I have this mWebView which changes loadUrl depending on the user action. I want this to happen from different class too.
and here is how I change loadUrl in MainActivity:
Now, in another class, ItemView, I want to switch to MainActivity but with different mWebView.loadUrl, depending on user action also. Hope you understand.
Here is what I tried in ItemView class:
This switch my app to MainActivity but everytime loadUrl is url1. url2 or url3 opens in system browser.
How can I fix this? I even tried to copy mWebView settings from the MainActivity, without success.
Thanks!
In MainActivity I have this mWebView which changes loadUrl depending on the user action. I want this to happen from different class too.
Code:
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
Context context = this;
mWebView.getSettings().setGeolocationDatabasePath(context.getFilesDir().getPath());
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new WebChromeClient() {
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
});
mWebView.loadUrl("http://google.com");
and here is how I change loadUrl in MainActivity:
Code:
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.firstmenu) {
mWebView.loadUrl("http://yahoo.com");
}
else if (id == R.id.secondmenu) {
mWebView.loadUrl("http://microsoft.com");
}
}
Now, in another class, ItemView, I want to switch to MainActivity but with different mWebView.loadUrl, depending on user action also. Hope you understand.
Here is what I tried in ItemView class:
Code:
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.firstmenu) {
Intent i = new Intent(ItemView.this, MainActivity.class);
startActivity(i);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.loadUrl("http://yahoo.com");
}
else if (id == R.id.secondmenu) {
Intent i = new Intent(ItemView.this, MainActivity.class);
startActivity(i);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.loadUrl("http://microsoft.com");
}
}
This switch my app to MainActivity but everytime loadUrl is url1. url2 or url3 opens in system browser.
How can I fix this? I even tried to copy mWebView settings from the MainActivity, without success.
Thanks!