What is the use of com.google.inject.Provider?

97 views
Skip to first unread message

Ishan Dave

unread,
Jun 9, 2014, 6:03:15 AM6/9/14
to robo...@googlegroups.com
When we have layered architecture why do we need to write and call the Provider so Injector can inject the object?


What is the user of Provider?

Thank you

Jeroen Tietema

unread,
Jun 9, 2014, 7:03:00 AM6/9/14
to robo...@googlegroups.com
A provider "provides" an instance of a dependency. It is optional to create a provider, as you can also directly bind a class. You typically use a provider when the object is not trivial to construct.
 
Does that make sense?
 
You can find more information about different bindings on the Google Guice site:
 
Cheers, Jeroen
--
You received this message because you are subscribed to the Google Groups "roboguice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roboguice+...@googlegroups.com.
To post to this group, send email to robo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ishan Dave

unread,
Jun 9, 2014, 8:45:20 AM6/9/14
to robo...@googlegroups.com, jer...@tietema.net
Hi Jeroen,

Thank you for your reply and information provided. Actually I am facing an issue from last couple of days.
In our application we are using some third party libraries. Now if something bad happend in the librarry code that we receives "Fatal Exception" and app crashes, so we re-start the activity. After this restart of activity Roboguice is not able to inject the dependencies and the app keep crashing just because of Roboguice, we are thinking to remove Roboguice from our app but I am in favour that there must be some way to avoid this concecutive crashes. This is why we are looking into 'Providers'.

Could you please suggest some way here as we really stucks at this point. If you need any further information please let us know.

Thank you again for your reply.

Jeroen Tietema

unread,
Jun 10, 2014, 12:59:03 AM6/10/14
to Ishan Dave, robo...@googlegroups.com
Are you referring to the stacktrace from the other thread?
 
If so:
The following line seems to be the problem. You are not calling super.onRestoreInstanceState() in your GalleryActivity
activity ComponentInfo{com.somepackage/com.somepackage.view.GalleryActivity}: java.lang.IllegalStateException: Derived class did not call super.onRestoreInstanceState()
 
If not:
Could you post a stacktrace of the crash. I would be really surprised if this is a RoboGuice problem. I suspect something is going wrong with the object you are trying to inject, but it is hard to tell without more information.
 
Cheers, Jeroen

Ishan Dave

unread,
Jun 10, 2014, 1:47:06 AM6/10/14
to robo...@googlegroups.com, ish...@gmail.com, jer...@tietema.net
Hi Jeroen,

Thank you very much for your reply and interest taken in the issue we are facing.

Are you referring to the stacktrace from the other thread?  - Nope.

Following is the detailed stacktrace, after first crash which was because of some issue in lib but we restarted the activity after the first crash and now the app keep crashing:

05-09 02:38:25.314: I/dalvikvm(14276): Could not find method com.google.inject.Injector.getAllBindings, referenced from method roboguice.inject.ContextScopedRoboInjector.getAllBindings
05-09 02:38:25.314: W/dalvikvm(14276): VFY: unable to resolve interface method 9207: Lcom/google/inject/Injector;.getAllBindings ()Ljava/util/Map;
05-09 02:38:25.314: D/dalvikvm(14276): VFY: replacing opcode 0x72 at 0x000c
05-09 02:38:25.314: I/dalvikvm(14276): Could not find method com.google.inject.Injector.getExistingBinding, referenced from method roboguice.inject.ContextScopedRoboInjector.getExistingBinding
05-09 02:38:25.314: W/dalvikvm(14276): VFY: unable to resolve interface method 9211: Lcom/google/inject/Injector;.getExistingBinding (Lcom/google/inject/Key;)Lcom/google/inject/Binding;
05-09 02:38:25.314: D/dalvikvm(14276): VFY: replacing opcode 0x72 at 0x000c
05-09 02:38:25.314: I/dalvikvm(14276): Could not find method com.google.inject.Injector.getScopeBindings, referenced from method roboguice.inject.ContextScopedRoboInjector.getScopeBindings
05-09 02:38:25.314: W/dalvikvm(14276): VFY: unable to resolve interface method 9219: Lcom/google/inject/Injector;.getScopeBindings ()Ljava/util/Map;
05-09 02:38:25.314: D/dalvikvm(14276): VFY: replacing opcode 0x72 at 0x000c
05-09 02:38:25.314: I/dalvikvm(14276): Could not find method com.google.inject.Injector.getTypeConverterBindings, referenced from method roboguice.inject.ContextScopedRoboInjector.getTypeConverterBindings
05-09 02:38:25.314: W/dalvikvm(14276): VFY: unable to resolve interface method 9220: Lcom/google/inject/Injector;.getTypeConverterBindings ()Ljava/util/Set;
05-09 02:38:25.314: D/dalvikvm(14276): VFY: replacing opcode 0x72 at 0x000c
05-09 02:38:25.594: D//Ln.java:218(14276): main Configuring Logging, minimum log level is VERBOSE
05-09 02:38:25.854: D/dalvikvm(14276): GC_FOR_ALLOC freed 4194K, 40% free 6690K/10968K, paused 18ms, total 18ms
05-09 02:38:25.884: D/dalvikvm(14276): GC_FOR_ALLOC freed 5K, 35% free 7192K/10968K, paused 8ms, total 8ms
05-09 02:38:25.884: I/dalvikvm-heap(14276): Grow heap (frag case) to 10.021MB for 973300-byte allocation
05-09 02:38:25.954: W/ContextImpl(14276): Failed to ensure directory: /storage/sdcard1/Android/data/somepackage/files/somepackage
05-09 02:38:26.194: D/dalvikvm(14276): GC_FOR_ALLOC freed 671K, 21% free 9515K/11920K, paused 12ms, total 12ms
05-09 02:38:26.194: I/dalvikvm-heap(14276): Grow heap (frag case) to 11.609MB for 260112-byte allocation
05-09 02:38:26.214: D/dalvikvm(14276): GC_FOR_ALLOC freed 449K, 22% free 9581K/12176K, paused 10ms, total 10ms
05-09 02:38:26.224: D/dalvikvm(14276): GC_FOR_ALLOC freed 188K, 20% free 9773K/12176K, paused 10ms, total 10ms
05-09 02:38:26.234: D/dalvikvm(14276): GC_FOR_ALLOC freed 307K, 21% free 9723K/12176K, paused 10ms, total 10ms
05-09 02:38:26.244: D/dalvikvm(14276): GC_FOR_ALLOC freed 62K, 20% free 9787K/12176K, paused 10ms, total 10ms
05-09 02:38:26.244: I/dalvikvm-heap(14276): Grow heap (frag case) to 11.875MB for 260112-byte allocation
05-09 02:38:26.264: D/dalvikvm(14276): GC_FOR_ALLOC freed 126K, 21% free 9915K/12432K, paused 10ms, total 10ms
05-09 02:38:26.264: I/dalvikvm-heap(14276): Grow heap (frag case) to 11.890MB for 145377-byte allocation
05-09 02:38:26.404: D/dalvikvm(14276): GC_FOR_ALLOC freed 887K, 16% free 10602K/12576K, paused 16ms, total 16ms
05-09 02:38:26.564: W/FileUtils(14276): Failed to chmod(/storage/emulated/0/Android/data/somepackage/files/somepackage/PiCamDB.sqlite): libcore.io.ErrnoException: chmod failed: EPERM (Operation not permitted)
05-09 02:38:26.614: D/dalvikvm(14276): GC_FOR_ALLOC freed 1444K, 13% free 11360K/12912K, paused 19ms, total 19ms
05-09 02:38:26.684: D/dalvikvm(14276): GC_FOR_ALLOC freed 20K, 9% free 12979K/14260K, paused 17ms, total 17ms
05-09 02:38:26.754: D/StaggeredGridView(14276): Request Layout
05-09 02:38:26.754: D/StaggeredGridView(14276): Request Layout
05-09 02:38:26.754: D/StaggeredGridView(14276): Request Layout
05-09 02:38:26.754: D/StaggeredGridView(14276): Request Layout
05-09 02:38:26.754: D/StaggeredGridView(14276): Request Layout
05-09 02:38:26.754: D/StaggeredGridView(14276): onChanged false
05-09 02:38:26.754: D/StaggeredGridView(14276): Recycle all views.
05-09 02:38:26.754: D/StaggeredGridView(14276): Request Layout
05-09 02:38:26.754: D/StaggeredGridView(14276): Request Layout
05-09 02:38:26.754: D/StaggeredGridView(14276): java.lang.ClassCastException: android.view.View$BaseSavedState cannot be cast to somepackage.common.customgridview.StaggeredGridView$SavedState
05-09 02:38:26.754: D/StaggeredGridView(14276): Request Layout
05-09 02:38:26.754: D/AndroidRuntime(14276): Shutting down VM
05-09 02:38:26.754: W/dalvikvm(14276): threadid=1: thread exiting with uncaught exception (group=0x4156ed58)
05-09 02:38:26.764: E/AndroidRuntime(14276): FATAL EXCEPTION: main
05-09 02:38:26.764: E/AndroidRuntime(14276): Process: somepackage, PID: 14276
05-09 02:38:26.764: E/AndroidRuntime(14276): java.lang.RuntimeException: Unable to start activity ComponentInfo{somepackage/somepackage.view.GalleryActivity}: java.lang.IllegalStateException: Derived class did not call super.onRestoreInstanceState()
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2248)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.ActivityThread.access$800(ActivityThread.java:138)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.os.Handler.dispatchMessage(Handler.java:102)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.os.Looper.loop(Looper.java:136)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.ActivityThread.main(ActivityThread.java:5050)
05-09 02:38:26.764: E/AndroidRuntime(14276): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 02:38:26.764: E/AndroidRuntime(14276): at java.lang.reflect.Method.invoke(Method.java:515)
05-09 02:38:26.764: E/AndroidRuntime(14276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
05-09 02:38:26.764: E/AndroidRuntime(14276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
05-09 02:38:26.764: E/AndroidRuntime(14276): at dalvik.system.NativeStart.main(Native Method)
05-09 02:38:26.764: E/AndroidRuntime(14276): Caused by: java.lang.IllegalStateException: Derived class did not call super.onRestoreInstanceState()
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.view.View.dispatchRestoreInstanceState(View.java:12801)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2637)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2643)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.view.View.restoreHierarchyState(View.java:12777)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.Fragment.restoreViewState(Fragment.java:613)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:910)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1044)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1853)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.Activity.performCreate(Activity.java:5234)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-09 02:38:26.764: E/AndroidRuntime(14276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
05-09 02:38:26.764: E/AndroidRuntime(14276): ... 11 more
05-09 02:38:28.964: I/Process(14276): Sending signal. PID: 14276 SIG: 9
05-09 02:38:29.084: D/PiCamApplication(14333): PiCamApplication update Sync Status
05-09 02:38:29.094: I/dalvikvm(14333): Could not find method com.google.inject.Injector.getAllBindings, referenced from method roboguice.inject.ContextScopedRoboInjector.getAllBindings

Please let us know if you need more information.

Thank you,
Ishan

Michael Burton

unread,
Jun 10, 2014, 11:03:42 AM6/10/14
to robo...@googlegroups.com, ish...@gmail.com, jer...@tietema.net
Are you using Proguard or another obfuscator/optimizer?  If so, try turning it off and see if the problem goes away
--

Michael Burton

unread,
Jun 10, 2014, 11:06:46 AM6/10/14
to robo...@googlegroups.com, ish...@gmail.com, jer...@tietema.net

Ishan Dave

unread,
Jun 10, 2014, 11:30:20 AM6/10/14
to robo...@googlegroups.com, ish...@gmail.com, jer...@tietema.net
Hi Michael,

Thank you for your reply.

No, we are not using Progaurd or any obfuscator/optimizer. We created a straightforward android project from eclipse, by default the android project has progaurd-project.txt but we are not using it.

Please share your thoughts so this will start working.

Thanks a lot for your inputs.

Thank you,
Ishan
To unsubscribe from this group and stop receiving emails from it, send an email to roboguice+unsubscribe@googlegroups.com.

To post to this group, send email to robo...@googlegroups.com.
Visit this group at http://groups.google.com/group/roboguice.
For more options, visit https://groups.google.com/d/optout.

Jeroen Tietema

unread,
Jun 10, 2014, 10:06:35 PM6/10/14
to Ishan Dave, robo...@googlegroups.com
The only problem I see is:
activity ComponentInfo{com.somepackage/com.somepackage.view.GalleryActivity}: java.lang.IllegalStateException: Derived class did not call super.onRestoreInstanceState()
 
I would suggest to fix that first.

Ishan Dave

unread,
Jun 11, 2014, 1:07:16 AM6/11/14
to robo...@googlegroups.com, ish...@gmail.com, jer...@tietema.net
Hi Jeroen,

Thank you for your input.

But, the problem starts from first line in stacktrace
05-09 02:38:25.314: I/dalvikvm(14276): Could not find method com.google.inject.Injector.getAllBindings, referenced from method roboguice.inject.ContextScopedRoboInjector.getAllBindings
05-09 02:38:25.314: W/dalvikvm(14276): VFY: unable to resolve interface method 9207: Lcom/google/inject/Injector;.getAllBindings ()Ljava/util/Map;

One more point would like to share is if we remove Roboguice things are working fine, but with Roboguice we are facing the issue.

Please share your thoughts here.

Thank you,
Ishan
Reply all
Reply to author
Forward
0 new messages