Open sidharthanil opened 7 years ago
I`m sorry I have no info about this problem, If you wish you can track it down and let us know your discoveries
i got the same problem ...cry!!!
got the same problem +1
I also encountered the same problem in Kotlin
I've also faced that problem, and in my case it was related to Kotlin object declaration. So if you also using an object as a fabric of Retrofit APIs, you can bypass the issue using by lazy
delegate.
Since I came here looking for solution, maybe my example will help a next wanderer:
object HttpApi {
lateinit private var cookiesHandler: CookieJar
fun updateCookieJarWithContext(context: Context) {
cookiesHandler = PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(context))
}
private val loggingInterceptor by lazy {
HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY }
}
private val httpClient by lazy {
OkHttpClient.Builder().apply {
addInterceptor(loggingInterceptor)
cookieJar(cookiesHandler)
}.build()
}
private val builder by lazy { Retrofit.Builder().addConverterFactory(JacksonConverterFactory.create()) }
private fun <ApiInterface> createService(serviceClass: Class<ApiInterface>, apiEndpointUrl: String = "rest") = builder
.baseUrl("https://***/$apiEndpointUrl/")
.client(httpClient)
.build()
.create(serviceClass)
val rest: HttpRestApi by lazy { createService(HttpRestApi::class.java) }
val auth: HttpAuth by lazy { createService(HttpAuth::class.java, "auth") }
}
Also I recommend to use a dependency injection framework, like Dagger, there is an example of application context injection.
I'm using full kotlin and meet the problem.
It turns out we don't have a persistent property always false to won't be saved in SharedPref.
After I rewrite the method saveFromResponse
to force save it. It works fine.
related issue #14 #15
@franmontiel why not just have an option to save all cookies regardless if they have max-age
or expires
attributes? Seems like this persistence thing is causing many people problems with your library including myself. I'm using Kotlin and building a login flow where I store some cookies from a request, navigate to a 3rd party app for logging in and then come back to my original app, and then to my surprise, some important cookies are lost.
Hi, I am using kotlin to do my android project. Im using this library on my other java projects on android and all of them works fine. But when I use this with kotlin the cookie is not getting saved. I want to know whether this has occured to you or do you know the work around for this issue?
I have manually checked using adb commands to read the shared prefrences. While on my java project the cokie is being set but here it isnt. Please respond fast