Comments (7)
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
from persistentcookiejar.
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.
from persistentcookiejar.
@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.
from persistentcookiejar.
I`m sorry I have no info about this problem, If you wish you can track it down and let us know your discoveries
from persistentcookiejar.
i got the same problem ...cry!!!
from persistentcookiejar.
got the same problem +1
from persistentcookiejar.
I also encountered the same problem in Kotlin
from persistentcookiejar.
Related Issues (20)
- When i get cookies Access the server ,sometime cookies is null ,
- Error:Cannot change dependencies of configuration ':app:_debugAnnotationProcessor' after it has been resolved.
- How to read cookies? HOT 2
- Proguard rules doesn't make sense?
- How to remove cookies for a target url? HOT 1
- Repo is unavailable HOT 4
- SetCookieCache may lead to ConcurrentModificationException HOT 1
- May I ask you something
- Invalid Cast HOT 3
- could not use chinese as login name (不能使用中文的登录名)
- Kill the process from the background, from the new entry NullPointerException error HOT 1
- Cookies are either not persisting, or not being sent out HOT 1
- Failed to resolve: com.github.franmontiel:PersistentCookieJar:v1.0.1 HOT 2
- If only there were .jar
- Google play rejected my app
- Issue with implementation of the Secure flag in cookies
- Share cookie with Webview HOT 2
- work with Glide
- Why are the results obtained cookie.value() = deleteMe ?
- Check if Cookie exists before making a network call
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from persistentcookiejar.