android从WebView关闭当前活动 [英] android close current activity from WebView

查看:65
本文介绍了android从WebView关闭当前活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WebView 并加载了一个网页,例如:example.com/x.html

i have a WebView and that load a web page like : example.com/x.html

现在在 x.html 中有一个提交按钮,这个文件被加载到我的 ShowActivity.java 中

now in x.html a have a submit button and this file is load into my ShowActivity.java

如何在用户点击提交按钮时关闭此活动?

how can i close this activity when user click on the submit button?

推荐答案

如果你可以点击按钮重定向

If you can redirect on button click something

然后

onClick="document.location.href='http://exitme';".

然后在您的 shouldOverrideUrlLoading 方法中,您可以拦截该 URL 并退出应用程序.

Then in your shouldOverrideUrlLoading method, you can intercept that URL and exit the app.

@Override 
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
    if (url.contains("http://exitme")
        finish();  // close activity
    else
        view.loadUrl(url);

    return true; 
}

这篇关于android从WebView关闭当前活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆