Hi,
sorry if it sounds like a duplicate, but I was wondering what's the differences between injecting a Context, and Application and a Provider<Context>?
So far, I've been Injecting Context, and everything was fine, but yesterday, I had a crash:
Error:
java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:57)
at roboguice.inject.ContextScope$1.get(ContextScope.java:108)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:53)
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:110)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:94)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)
at com.google.inject.assistedinject.FactoryProvider2.invoke(FactoryProvider2.java:632)
at $Proxy6.createChannelViewHolder(Native Method)
I googled and found that it could be Context related. So I Injected an Application (and called getApplicationContext), and the problem went away. Same with using Provider<Context>
I need a Context in order to:
- manipulate files (openFileInput, deleteFile, getFileStreamPath)
- start an IntentService
- get Inflater (I'm generating ViewHolder on the fly, to be populated in an Adapter)
Those tasks happen without UI, so I can't really pass an Activity or a Context all the was down to them.
so I'm not sure what I should use...
Thanks for your help!