从网络视图重定向到新 activity
Redirecting from a web view to a new activity
在此应用程序中,我正在尝试创建一个登录页面 "Main activity 1" 以显示 login/registration 网站。然后只有在用户成功登录后我才想显示第二个 activity 。我知道我可以使用解析来创建一个 SQL 数据库,但在这种情况下我想避免这种情况并使用我的网站来处理注册/登录数据库 ("tell me based on your experience if it is a stupid idea ").
public class MainActivity extends AppCompatActivity {
//move to second activity only afther login
WebView webView;
public class webView() {
if (webView.loadUrl("login URL")!= webView.loadUrl("login URL")){ //need help here
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);
}
return ;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// DISPALY WEBSITE FOR LOGIN
webView = findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("login URL");
}
}
您可以添加 webview 侦听器并可以在用户登录时触发新的 activity,您可以通过以下代码。
webview.setWebViewClient(new WebViewClient()
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
//Here check whether the url is after logged in
if(url.equals("URL after user logged In")){
//start new activity
}
}
@Override
public void onPageFinished(WebView view, String url) {
Log.d("WebView", "your current url when webpage loading.. finish" + url);
super.onPageFinished(view, url);
}
@Override
public void onLoadResource(WebView view, String url) {
// TODO Auto-generated method stub
super.onLoadResource(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out.println("when you click on any interlink on webview that time you got url :-" + url);
return super.shouldOverrideUrlLoading(view, url);
}
});
希望对您有所帮助。
在此应用程序中,我正在尝试创建一个登录页面 "Main activity 1" 以显示 login/registration 网站。然后只有在用户成功登录后我才想显示第二个 activity 。我知道我可以使用解析来创建一个 SQL 数据库,但在这种情况下我想避免这种情况并使用我的网站来处理注册/登录数据库 ("tell me based on your experience if it is a stupid idea ").
public class MainActivity extends AppCompatActivity {
//move to second activity only afther login
WebView webView;
public class webView() {
if (webView.loadUrl("login URL")!= webView.loadUrl("login URL")){ //need help here
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);
}
return ;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// DISPALY WEBSITE FOR LOGIN
webView = findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("login URL");
}
}
您可以添加 webview 侦听器并可以在用户登录时触发新的 activity,您可以通过以下代码。
webview.setWebViewClient(new WebViewClient()
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
//Here check whether the url is after logged in
if(url.equals("URL after user logged In")){
//start new activity
}
}
@Override
public void onPageFinished(WebView view, String url) {
Log.d("WebView", "your current url when webpage loading.. finish" + url);
super.onPageFinished(view, url);
}
@Override
public void onLoadResource(WebView view, String url) {
// TODO Auto-generated method stub
super.onLoadResource(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out.println("when you click on any interlink on webview that time you got url :-" + url);
return super.shouldOverrideUrlLoading(view, url);
}
});
希望对您有所帮助。