java – Android WebView for the personal account of the site

Question:

I use WebView to display the personal WebView page on the site. All operations are processed on the server side (i.e. just the mobile version of the site is loaded). Previously, I did not work with this component, which raises a number of questions:

  1. What are the "pitfalls" in the implementation of this task?
  2. Are there any mechanisms for protecting or caching data? Is it necessary at all?
  3. If, for example, the user is logged in, will this state be persisted on the client side (i.e. mobile application) or on the server side?
  4. What other seemingly obvious things are there that need to be implemented?

As it seems to me, it can't be that simple: create a WebView , assign a default page to it, and that's it.

Answer:

If you need to clear cookies, look to the side:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        Log.d(C.TAG, "Using ClearCookies code for API >=" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else
    {
        Log.d(C.TAG, "Using ClearCookies code for API <" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
        CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager=CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }

Next, you will need to intercept the clicks on the links so that they open in the same window:

new WebViewClient() {  
  @Override  
  public boolean shouldOverrideUrlLoading(WebView view, String url)  
  {  
    view.loadUrl(url); //this is controversial - see comments and other answers
    return true;  
  }  
});        
Scroll to Top