I am loading a web app from my android application. In the initial load of URL, it will redirect to the login page and after login, it will move to the web app home screen. But the expected behaviour is to redirect it to Native Homescreeb after login. So I have written intent to launch new activity in onPageFinished by comparing the URL. But it will show the Web page for 2 seconds before moving to Activity. I tried hiding Webview on that case. Then a blank screen is displayed for 2seconds and an Activity is displayed. See below implementation and correct me if anything is wrong.
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
try {
String loadingURL =request.getUrl().toString();
view.loadUrl(request.getUrl().toString());
} catch (Exception e) {
}
return true;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
try{
handler.proceed();
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if(url.contains("https://login.microsoftonline.com/"))
{
mWebview.setVisibility(View.VISIBLE);
}
else if(url.contains(GlobalDeclarations.BASE_URL_WEBAPP_DEV) )
{
progress_div.setVisibility(View.VISIBLE);
mWebview.setVisibility(View.GONE);
}
}
@Override
public void onPageCommitVisible(WebView view, String url) {
super.onPageCommitVisible(view, url);
Log.d("onPageCommitVisible", "onPageCommitVisible" + url);
}
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
if (mWebview.getProgress() == 100) {
if(url.contains(GlobalDeclarations.BASE_URL_WEBAPP_DEV))
{
mWebview.setVisibility(View.GONE);
}
else
{
mWebview.setVisibility(View.VISIBLE);
}
progress_div.setVisibility(View.GONE);
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.d("onPageFinished", "onPageFinished URL........ " + url );
mWebview.evaluateJavascript("common.setFromApp(" + true + ")", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
if (value.equals("false"))
{
mWebview.setVisibility(View.GONE);
Intent intent = new Intent(view.getContext(), BaseActivity.class);
startActivity(intent);
}
else
{
mWebview.setVisibility(View.VISIBLE);
}
}
});