如何找回从网页视图的android活动页面 [英] how to get back to android activity page from webview

查看:126
本文介绍了如何找回从网页视图的android活动页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,如果点击了网页视图一个注销按钮(这是一个春天的应用程序),页面回过头来看看Android的登录页面。这可能吗?在code是一个.js文件。我希望它像

 如果(btnlogout.clicked),然后
            去意向意图=新意图(menu​​ScreenActivity.this,
                        LoginActivity.class);


解决方案

嗯,也许哟需要你的WebView和你的java code,你可以在这里看到集成:

http://developer.android.com/guide/webapps/webview.html

绑定的JavaScript code到Android code

 的WebView myWebView =(的WebView)findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(真);
webView.addJavascriptInterface(新JavaScriptInterface(本),机器人);

所以,你告诉在这里,你的WebView可以使用运行JavaScript,并能够访问到你的java $ C $在JavaScriptInterface类可用C和使用JS像这样的公共方法:

 <输入类型=按钮值=问好的onClick =showAndroidToast('您好!Android的')/><脚本类型=文/ JavaScript的>
    功能showAndroidToast(吐司){
        Android.showToast(面包);
    }
< / SCRIPT>

在JavaScript中的行 Android.showToast(面包); 和Android是你在这里选用的名称 webView.addJavascriptInterface(新JavaScriptInterface(本),机器人);

showToast 在JavaScriptInterface类的公共方法包含你所需要的,也可在这种情况下:

  **公共无效showToast(字符串吐司){
    Toast.makeText(mContext,烤面包,Toast.LENGTH_SHORT).show();
} **

抄袭这一切都来自链接...我觉得这个回答你的问题,你可以创建你的方法调用注销该做necesary的东西,如:

 意向意图=新意图(menu​​ScreenActivity.this,LoginActivity.class);

So if a logout button is clicked on the webview (which is a spring app), the page should get back to the android login page. is this possible? the code is on a .js file. i want it like

        if(btnlogout.clicked) then 
            go to Intent intent = new Intent(menuScreenActivity.this,
                        LoginActivity.class);

解决方案

Hmmm maybe yo need to integrate your webview and your java code as you can see here:

http://developer.android.com/guide/webapps/webview.html

Binding JavaScript code to Android code

WebView myWebView = (WebView) findViewById(R.id.webview); 
WebSettings webSettings = myWebView.getSettings(); 
webSettings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");

So, you are Telling here that your webview can use run javascript and will be able to access to your java code available at JavaScriptInterface class and its public methods on using js like this way:

<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />

<script type="text/javascript">
    function showAndroidToast(toast) {
        Android.showToast(toast);
    }
</script>

The line on javascript is Android.showToast(toast); and Android is the name you choosed here webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");

showToast is a public method on JavaScriptInterface CLASS containing what ever you need, in this case:

**public void showToast(String toast) {
    Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}**

just copied all this from that link... i think this answer your question, you can create your method called Logout that do the necesary stuff like:

Intent intent = new Intent(menuScreenActivity.this,LoginActivity.class);

这篇关于如何找回从网页视图的android活动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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