Hello, I am having some difficulties with Ktor's C...
# ktor
v
Hello, I am having some difficulties with Ktor's CookieStore disappearing overtime in Android, perhaps you could kindly take a look at my original question and suggest the cause and a solution? https://kotlinlang.slack.com/archives/C0B8M7BUY/p1717431696620719
s
If the cookies are stored in memory indeed, then you gotta expect them to disappear at some point. How long do you want them to exist for? Is a more permanent storage an option for you, like DataStore?
v
Thank you for your reply. I'd expect the session cookie to last throughout the lifetime of the app being on. I persist the session cookie inside EncryptedSharedPreferences and on the app's initial start up I take that cookie from there and put it into the Ktor's CookieStore. Could you suggest how I can keep this cookie inside the CookieStore without running the risk of it disappearing? Perhaps I could make sure it is there with onResume? Are there better/ more accepted ways? Maybe the whole approach is wrong?
s
I'm gonna be honest and tell you that I haven't worked with CookieStore before. I mainly wanted to say that losing in-memory things is a normal thing to happen if you just background your app and come back to it sometime later. The OS may decide to kill it at any point really. When you say "the entire time the app being on" do you mean you actually never exit your app and you still lose your state? Does CookieStore allow you to decide yourself where the stored cookies will be? Sounds like you're storing things in shared prefs, do you see that the cookie is deleted from shared prefs too?
v
Opposite to cookie store, the session cookie doesn't leave the shared prefs and remains there. Yes, the app is never fully closed (swiped away), at most it is backgrounded and this is when it appears the cookie store dies
s
v
Thank you, I shall try checking the cookie store and potentially readding it inside application context's onRestart()