'i cannot do multiple windows twice (webview) at the same running app , only once

how to make a new window after closing the old multiple window. the steps are:

  1. app loaded
  2. go to login page
  3. click google button
  4. pop up opened with annoying size
  5. logged in
  6. logout
  7. go to login page
  8. click google button
  9. here is the problem, not showing pop up again.

here is the video. https://youtu.be/W2sCeSnv0BQ

(problem at 00:58) video is 2 mins.

my code main.activity

public class MainActivity extends AppCompatActivity {


WebView web;
public boolean cekstatus;
private int SECOND_ACTIVITY_REQUEST_CODE = 0;
public static final String USER_AGENT_FAKE = "Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    web = findViewById(R.id.webView);

    WebSettings webSettings = web.getSettings();

    webSettings.setBuiltInZoomControls(true);
    webSettings.setSupportMultipleWindows(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);

    webSettings.setJavaScriptEnabled(true);
    webSettings.setUserAgentString(webSettings.getUserAgentString().replace("; wv",""));

    web.setWebViewClient(new Callback());
    web.setWebChromeClient(new WebChromeClient() {

            @Override
            public boolean onCreateWindow(WebView view, boolean isDialog,
                                          boolean isUserGesture, Message resultMsg) {

                WebView newWebView = new WebView(MainActivity.this);
                newWebView.getSettings().setUserAgentString(webSettings.getUserAgentString().replace("; wv",""));
                newWebView.getSettings().setJavaScriptEnabled(true);
                newWebView.getSettings().setSavePassword(true);
                newWebView.getSettings().setSaveFormData(true);
                newWebView.getSettings().setSupportMultipleWindows(true);
                newWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
                newWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
                web.addView(newWebView);
                WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
                transport.setWebView(newWebView);
                resultMsg.sendToTarget();


                newWebView.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {

                        return false;
                    }

                    public boolean shouldOverrideUrlLoading(WebView view, String url) {

                        if (url.startsWith("intent")) {
                            try {
                                Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                                String fallbackUrl = intent.getStringExtra("browser_fallback_url");
                                if (fallbackUrl != null) {
                                    view.loadUrl(fallbackUrl);
                                    return true;
                                }
                            } catch (URISyntaxException e) {

                            }
                        }
                        if (url.startsWith("tel:")) {
                            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                            startActivity(intent);
                        } else if (url.startsWith("mailto:")) {
                            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(url));
                            startActivity(intent);
                        } else  if (url.startsWith("whatsapp://")) {
                            view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                            return true;
                        } else if (url.startsWith("https://jai-indonesia.com/auth/")){
                            web.clearHistory();

                            newWebView.clearCache(true);
                            web.clearCache(true);
                            view.loadUrl(url);

                            web.reload();

                            Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                public void run()
                                {
                                    web.loadUrl("https://jai-indonesia.com/");
                                }
                            }, 1700);
                        } else if (url.startsWith("https://jai-indonesia.com/login")){
                           
                            clearAppData();
                            CookieManager.getInstance().removeAllCookie();
                            CookieManager.getInstance().flush();
                            CookieSyncManager.getInstance().sync();
                            WebStorage.getInstance().deleteAllData();
                            web.clearCache(true);
                            web.clearFormData();
                            web.clearHistory();
                            web.clearSslPreferences();
                            return true;
                        } else if (url.startsWith("https://jai-indonesia.com/sociallogin")){

                            WebStorage.getInstance().deleteAllData();


                            CookieManager.getInstance().removeAllCookies(null);
                            CookieManager.getInstance().flush();
                            CookieSyncManager.getInstance().sync();
                            web.clearCache(true);
                            web.clearFormData();
                            web.clearSslPreferences();
                        }

                        view.loadUrl(url);
                        return true;


                    }
                });
                return true;
            }
        });

    web.loadUrl("http://jai-indonesia.com");
}

private void clearAppData() {
    try {
        Runtime runtime = Runtime.getRuntime();
        runtime.exec("pm clear " + getApplicationContext().getPackageName() + " HERE");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private class Callback extends WebViewClient {
    @Override
    public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {

        return false;
    }

   
    public boolean shouldOverrideUrlLoading(WebView view, String url) {


        if (url.startsWith("intent")) {
            try {
                Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                String fallbackUrl = intent.getStringExtra("browser_fallback_url");
                if (fallbackUrl != null) {
                    view.loadUrl(fallbackUrl);
                    return true;
                }
            } catch (URISyntaxException e) {
                // Syntax problem with uri
            }
        }
        if (url.startsWith("tel:")) {
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
            startActivity(intent);
        } else if (url.startsWith("mailto:")) {
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(url));
            startActivity(intent);
        } else  if (url.startsWith("whatsapp://")) {
            view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;
        } else if (url.startsWith("https://jai-indonesia.com/login")){
           
            clearAppData();
            CookieManager.getInstance().removeAllCookie();
            CookieManager.getInstance().flush();
            CookieSyncManager.getInstance().sync();
            WebStorage.getInstance().deleteAllData();
            web.clearCache(true);
            web.clearFormData();
            web.clearHistory();
            web.clearSslPreferences();
            return true;
        } else if (url.startsWith("https://jai-indonesia.com")){

            // Clear all the Application Cache, Web SQL Database and the HTML5 Web Storage
            WebStorage.getInstance().deleteAllData();

            // Clear all the cookies
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
            CookieSyncManager.getInstance().sync();
            web.clearCache(true);
            web.clearFormData();
            web.clearHistory();
            web.clearSslPreferences();
        }
         else if (url.startsWith("https://jai-indonesia.com/auth/google/")){
            web.loadUrl("https://jai-indonesia.com/");
            Handler handler = new Handler();
            handler.postDelayed(new Runnable()
            {
                public void run()
                {
                    web.loadUrl("https://jai-indonesia.com/");
                }

            }, 1700);
          }
         else if (url.startsWith("https://jai-indonesia.com/sociallogin")){
            // Clear all the Application Cache, Web SQL Database and the HTML5 Web Storage
            WebStorage.getInstance().deleteAllData();

            // Clear all the cookies
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
            CookieSyncManager.getInstance().sync();
            web.clearCache(true);
            web.clearFormData();
            web.clearSslPreferences();
        }

        view.loadUrl(url);
        return false;
    }

}


// Additional code.

@Override
public void onBackPressed() {
    if (web!=null){
        if (web.canGoBack()){
            web.goBack();
            return;
        }
    }


        super.onBackPressed();

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source