0

I am currently developing an app using Android webView however, I have ran into a problem. When a user logs into the app a cookie is created for them, this cookie is then used to check who they are throughout all the web pages. But, when the app is closed and reopened the cookies are lost. Is there any way that I am able to stop the cookies from being removed each time the app is closed.

This is my code for the webView:

String url = "http://app.tantami.co.uk/activity_hpv/uk.co.tantami.app/load.php?app_id=1.1";
WebView view = (WebView) this.findViewById(R.id.web1);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
view.setWebViewClient(new WebViewClient());
James Walsh
  • 41
  • 2
  • 10

1 Answers1

1

You have to use CookieSyncManager to save it, ex:

webview.setWebViewClient(new WebViewClient() {
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {

        Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
    }

    public void onPageFinished(WebView view, String url) {
        CookieSyncManager.getInstance().sync();
    }
);