gpt4 book ai didi

javascript - 当特定的url加载时关闭android webview?

转载 作者:行者123 更新时间:2023-12-01 01:09:58 25 4
gpt4 key购买 nike

我有基本的 android webview。它是一个注册页面。我想在注册后关闭此 webview 并启动新的 Intent 。我对此不熟悉,请帮忙。这是我的代码。

public class signupweb extends AppCompatActivity {
private WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signupweb);
webView = (WebView) findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl("http://aaa.freeasphost.net/signup.aspx");

WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}

private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
if (url.equals("http://aaa.freeasphost.net/MainPanel.aspx")) {
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
return false;
} else {

return true;
}
}
// }

我尝试了这个,但不起作用。它卡在注册页面

最佳答案

您需要传递context才能启动新 Activity 。试试这个:

private class MyWebViewClient extends WebViewClient {

private Context context;

public MyWebViewClient(Context context) {
this.context = context;

}

@Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
if (url.equals("http://aaa.freeasphost.net/MainPanel.aspx")) {
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
context.startActivity(intent);
return false;
} else {

return true;
}
}

关于javascript - 当特定的url加载时关闭android webview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55253303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com