I've written an app for Android that uses a webview to submit information via check boxes to a MYSQl back end. Right now to exit from the webview, the user has to use the keys on the device to continue to the next app activity. Is there some way to detect the form submission button has been pressed by the app and then use something, say an Intent to go to the next activity (closes webview and then NextActivity.class), preferably without javascript? I've tried a shouldOverrideUrlLoading by having a new page called when the submit button is pressed, then calling an if statement with (Uri.parse(url).getHost().equals("page url")){Intent...} with no luck. Thanks in advance! Here is the coded page:
public class WebViewActivity extends Activity {
private WebView webView;
int backButtonCount = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
//webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
Bundle extras = getIntent().getExtras();
if(extras!=null){
String rode=extras.getString("rode");
}
String ray = extras.getString("rode");
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://mywebsite.com/SubDir/user_man.php?user=" + ray);
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).equals("http://mywebsite.com/SubDir/process_prof.php")) {
return false;
}
Intent ik = new Intent(WebViewActivity.this, master_menu.class);
startActivity(ik);
finish();
return true;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_bar_two, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.action_selected){
Intent iw = new Intent(this,GetUserEmail.class);
startActivity(iw);
finish();
}
else
if (item.getItemId()==R.id.action_cancel){
Intent iw = new Intent(this,RegisterActivity.class);
startActivity(iw);
finish();
}
return true;
}
public void onBackPressed()
{
if(backButtonCount >= 1)
{
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else
{
Toast.makeText(this, "Press the back button again to close.", Toast.LENGTH_SHORT).show();
backButtonCount++;
}
}
Got it working, here is the fix for others:
}
I believe the issue with your if statement is the getHost() which will return only the host name (www.google.com) and not the whole URL. Try removing that and I believe your if statement will return true if it matches.