开发者

Android WebView- remember username and password

I am making a basic WebView app that will load a web page. This web page requires log in information. When I navigate out or refresh the page it logs me out. How do I stay logged in? The following code is my attempt based on some research but apparently I am not understanding the concept. And so I can kill two bird with on开发者_开发百科e stone, can someone let me know how to prevent a refresh of the page when you rotate your phone? is this possible? Thanks for any help in advanced.

    public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  mWebView = (WebView) findViewById(R.id.webview);
  mWebView.getSettings().setJavaScriptEnabled(true);
  mWebView.loadUrl("www.randomurl.com");
  mWebView.setWebViewClient(new HelloWebViewClient());
  CookieSyncManager.createInstance(this);
  CookieSyncManager.getInstance().startSync();
  CookieManager.getInstance();
 }


The two problems i posted were actually related. Apparently whenever a orientation change or when i navigated out of the web page, the data would be destroyed so i added this method

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

Hopefully this will be useful for other people!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜