I am creating an android application in xamarin. I am using a web view to display a website. After user login website create a cookie and should store in web view. There are two web view in app, One web view is displaying the pages and if there is any text box in the page that page is opened in second web view.
So now when user tries to login, second web view is opened(as login page contains text box), after user enter details and click next button, the second view is closed and next page is opened in first web view. After login a cookie is created and stored in web view and when user open the app next time its doesn't asks for login. This is what should happen.
The problem is, if the user enter details and after clicks the next button(next page is loading in first web view) and immediately quits the application then start app again then cookies does not exists and app asks for login again.
After login I am reading the cookie value on page finish event of webview and displaying in toast. If i quits the app after login, i gets the cookie value in toast but when i starts the app again the cookie doesn't exists anymore and it asks me for login again
public override void OnPageFinished (WebView view, string url)
{
try
{
if (view.Url == Urls.URL_INDEX)
{
var cookieManager = CookieManager.Instance;
if (cookieManager != null)
{
//getcookie string from the url
string cookie = cookieManager.GetCookie (view.Url);
if (!string.IsNullOrEmpty (cookie))
{
string[] cookies = cookie.Split (';');
foreach (var newcookie in cookies)
{
if (newcookie.Trim().StartsWith (Constants.COOKIE_NAME))
{
string cookieValue = newcookie.Substring (newcookie.IndexOf ('='));
Toast.MakeText(activity,cookieValue,ToastLength.Short).Show();
}
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine ("Exception in storing cookie in Home Activity : "+ex.Message);
Toast.MakeText (activity, "Exception : " + ex.Message,ToastLength.Long).Show();
}
}
I don't know why this is happening, please help.