Inconsistent Injections

43 views
Skip to first unread message

Trey Wheeler

unread,
Dec 31, 2013, 4:30:24 PM12/31/13
to robo...@googlegroups.com
I'm working on a ViewModel framework for android that depends on Roboguice. I inject values into an activity's ViewModel at the same time in the activity's lifecycle every time I launch an activity that follows this pattern. This works 99.95% of the time. All of my injections are populated the way I expect and life is wonderful. Then, the other 0.05% of the time a variable will have a null supplied for it's injection, and code that assumed proper injection starts throwing NullPointerExceptions. If the user closes the activity and reopens it, everything works; all of the variables were injected as expected.

This appears to only happen when our application is running in "offline mode", which uses a series of supporting objects that increase our memory usage by about 7MB, putting us at 20MB or more depending on the situation. While there is room for improvement here, I wouldn't expect it to be causing the issue.

My questions are:

What could cause Roboguice to inject nulls in place of easily injectable concrete classes?

How does Roboguice behave if allocated memory is high?

Thanks for your time,
Trey

Michael Burton

unread,
Dec 31, 2013, 6:18:02 PM12/31/13
to robo...@googlegroups.com
There's no special behavior for low memory situations, so I expect that memory use is a red herring.  Is it possible that RoboGuice injection is getting called multiple times to inject the same object?  Just speculating, but i've seen what seemed like non-deterministic behavior in the past come from multiple injection passes.

--
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.
Visit this group at http://groups.google.com/group/roboguice.
For more options, visit https://groups.google.com/groups/opt_out.

Trey Wheeler

unread,
Jan 8, 2014, 6:21:16 PM1/8/14
to robo...@googlegroups.com
Thank you for the quick reply. I apologize for my belated one.
   I'm fairly confident that the ViewModel is not being injected to twice. The only point of injection is during Activity.onCreate.

Attached is my ViewModel class. The NullPointerException happens on line 357:
RESTCallResult<Module> result = _moduleProvider.GetModuleBy(getModuleID());

This is a method call inside of an AsyncTask wrapper, FetchTask. This task is created inside of an anonymous class, IAction, that I'm using as an asynchronous handler. Could the layering of these anonymous classes and the use of an injection on a background thread be at fault here? I am not inheriting RoboAsyncTask.

Thanks again,
Trey
FormViewModel_Offline.java
Reply all
Reply to author
Forward
0 new messages