MKK
MKK

Reputation: 2753

How can I store cookie in webview?

The webview of my app won't store cookie so that I have login again if I restart my app.

To store cookie, what should I add to this codes?
Can anyone show me with code using my original code?

public class MainActivity extends Activity {

    private ActionBar mActionBar;
    private SimpleSideDrawer mNav;
    WebView myWebView;  

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myWebView = (WebView)findViewById(R.id.webView1);
        myWebView.setWebViewClient(new WebViewClient());
        myWebView.getSettings().setJavaScriptEnabled(true);
        myWebView.loadUrl("http://example-site.com");          
        myWebView.getSettings().setSupportZoom(true); 
        myWebView.getSettings().setLoadWithOverviewMode(true);
        myWebView.getSettings().setUseWideViewPort(true); 
    .....
    }
....
}

Upvotes: 0

Views: 377

Answers (1)

Bouchehboun Saad
Bouchehboun Saad

Reputation: 728

you can store the cookie and retrieve them on app start like expline here Android WebView Cookie Problem

Upvotes: 2

Related Questions