Reputation: 545
I'm struggling with crosswalk and cordova plugin javacode to let them share the same cookies.
In javascript an authentication cookie is created and updated during several XMLHttpRequest
s to my webservice.
In Java, I have an IntentService
which onHandleIntent
gets called, for example when a location-update occures.
Inside of my onHandleIntent
I want to call the same webservice as the javascript part mentioned above using the same cookies.
To retrieve the cookies I call new XWalkCookieManager().getCookie(url)
and use it to make an HTTP-Call in Java including that cookie.
When the app is completly closed (via TaskManager), my onHandleIntent
is still called. But I cannot call getCookie(url)
since crosswalk is not running. getCookie(url)
crashes uncatchable (ndk).
I already tried to cache the current cookie in my MainActivity
s onStop
, and it works on some device. But on other devices the app often gets closed without proper stop behaviour. So this is very fragile.
So my question is: Is there a way to either get crosswalks cookies when the app is closed or to intercept all requests done by javascript and cache the cookie to have the right one ready when the app is closed?
Upvotes: 0
Views: 374
Reputation: 545
Since someone asks how I solved it, here is my heavy workaround, that contains 3 parts.
SharedPreferences
-String.SharedPreferences
, don't ask crosswalk to get cookie at all.XWalkCookieManager.setCookies
is also not possible when app is in killed state.
So I extended MainActivity
(with cordova hooks after platform add) to contain a BroadcastReciever
that writes back cookies to crosswalk.
The response-callback will store the new cookies in SharedPreferences
AND will send out a broadcast. If the app is running, the BroadcastReciever
exists and writes the cookie. If the app is in killed, the MainActivity
doesn't run so this broadcast will just be ignored.
The last important part is, on every appstart the cookie also must be readed from SharedPreferences
and write into crosswalk, because you missed those cookies during app-downtime.Hope that helpes, feel free to ask/comment again if something is unclear since it is a very confusion workaround.
Upvotes: 1