在此应用程序中,我试图拥有登录页面“主要活动1”以显示登录/注册网站。然后,只有在用户成功登录后,我才想显示第二个活动。我知道我可以使用解析来创建SQL DB,但是在这种情况下,我想避免这种情况,并使用我的网站来处理注册/登录数据库(“如果您的想法很愚蠢,请告诉我”)。 / p>
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");
}
}
答案 0 :(得分:0)
您可以添加webview侦听器,并可以在用户登录时触发新活动,您可以浏览以下代码。
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);
}
});
希望这会有所帮助。