ContextManager requiring activity even when called from background
Closed this issue · 11 comments
I'm currently making a authenticated call using Retrofit2 in a SyncAdapter. This Adapter runs in the background, so it fails when the app is not open (because there are no activities).
Any solution for this?
com.andretietz.retroauth.AuthenticationCanceledException: java.util.EmptyStackException
W/System.err: at com.andretietz.retroauth.CredentialInterceptor.storeAndThrowError(CredentialInterceptor.java:91)
W/System.err: at com.andretietz.retroauth.CredentialInterceptor.intercept(CredentialInterceptor.java:75)
W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
W/System.err: at okhttp3.RealCall.execute(RealCall.java:57)
W/System.err: at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
W/System.err: at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:89)
W/System.err: at com.imin.phone.sync.SyncAdapter.onPerformSync(SyncAdapter.java:71)
W/System.err: at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:272)
W/System.err: Caused by: java.util.EmptyStackException
W/System.err: at java.util.Stack.peek(Stack.java:57)
W/System.err: at com.andretietz.retroauth.ContextManager$LifecycleHandler.getCurrent(ContextManager.java:147)
W/System.err: at com.andretietz.retroauth.ContextManager.getActivity(ContextManager.java:90)
W/System.err: at com.andretietz.retroauth.AndroidTokenStorage.getToken(AndroidTokenStorage.java:54)
W/System.err: at com.andretietz.retroauth.AndroidTokenStorage.getToken(AndroidTokenStorage.java:35)
W/System.err: at com.andretietz.retroauth.CredentialInterceptor.intercept(CredentialInterceptor.java:67)
This is not supposed to happen. It's a bug. I'll fix this next week.
When calling authenticated requests in background, the requests are supposed to be executed as long as a valid token is available.
Ah yes, didn't notice I was running a older version. I'll check to confirm this first thing tomorrow morning, thanks!
It's not in the current version yet. It'll be in the snapshot version, in a few minutes
It's in the current snapshot version (2.1.3-SNAPSHOT) and tested:
https://github.com/andretietz/retroauth/blob/master/retroauth-android/src/test/java/com/andretietz/retroauth/ContextManagerTest.java#L37
Seems you forgot to tag it?
Since it's not a public release yet, no Tag is required. When the release will be out, I'll tag it. btw Snapshots will be build automatically as soon as it is in master
Don't forget adding
maven { url('https://oss.jfrog.org/artifactory/oss-snapshot-local') }
then use
compile 'com.andretietz.retroauth:retroauth-android:2.1.3-SNAPSHOT'
ah yes, thanks!
Seems the com.andretietz.retroauth:retroauth-android:2.1.3-SNAPSHOT is missing the provider and tokenstorage from core? Is it me or didn't it compile the dependency on retroauth-core project?