-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Injection Transfuse Activity into Calltrough listener #118
Comments
Are you also injecting the MenuController into your Try this: public class MenuController implements ActivityMenuComponent {
private MenuInflater menuInflater;
private Context context; // this is of the generated class SearchActivityActivity
private Provider<SearchActivity> activityProvider;
@Inject
public MenuController(MenuInflater menuInflater, Context context, Provider<SearchActivity> activityProvider) {
this.menuInflater = menuInflater;
this.context = context;
this.activityProvider = activityProvider;
} |
Ah, so that's what causes the problem. |
Shoot. You'll have to break the dependency loop by either injecting Here's how to inject via the interface: @Activity
public class SearchActivity{
@Inject MenuController controller;
}
public interface MenuController {}
public class MenuControllerImpl implements ActivityMenuComponent, MenuController {}
@TransfuseModule
@Bind(type=MenuController.class, to=MenuControllerImpl.class)
public class Module{} |
I tried the bind based injection. No errors on compile, but the callthrough listeners aren't registered anymore. |
Shoot, you may have to move the ActivityMenuComponent interface to as superclass of MenuController: public interface MenuController extends ActivityMenuComponent{}
public class MenuControllerImpl implements MenuController {} Are you using |
RegisterListener is in SearchActivity: @Inject
@RegisterListener
MenuController menu; If I extend ActivityMenuComponent, I get the following error:
The generated code looks like this @Generated(value = "org.androidtransfuse.TransfuseAnnotationProcessor", date = "2014-06-26T10:47+0200")
public class MenuControllerImpl$$VProxy$$0
implements MenuController, DelayedLoad<MenuControllerImpl>
{
private MenuControllerImpl delegate = null;
public void load(MenuControllerImpl delegateInput) {
delegate = delegateInput;
}
private void checkDelegate() {
if (delegate == null) {
throw new VirtualProxyException("Trying to use a proxied instance before initialization");
}
}
public boolean equals(Object object$$0) {
checkDelegate();
return delegate.equals(object$$0);
}
public int hashCode() {
checkDelegate();
return delegate.hashCode();
}
public String toString() {
checkDelegate();
return delegate.toString();
}
} |
I went ahead and duplicated this problem. I was able to make it work by changing the activityProvider back to just an activity injection and duplicating the callthrough method interface on public interface MenuController extends ActivityMenuComponent {
boolean onCreateOptionsMenu(Menu menu);
boolean onPrepareOptionsMenu(Menu menu);
boolean onOptionsItemSelected(MenuItem menuItem);
boolean onMenuOpened(int featureId, Menu menu);
void onOptionsMenuClosed(Menu menu);
} public class MenuControllerImpl implements MenuController {
private MenuInflater menuInflater;
private Context context; // this is of the generated class SearchActivityActivity
private SearchActivity activity;
@Inject
public MenuControllerImpl(MenuInflater menuInflater, Context context, SearchActivity activity) {
this.menuInflater = menuInflater;
this.context = context;
this.activity = activity;
}
//... Let me know if this gets you farther. Although this works, this is obviously not as nice as it could be... lets keep this open as a bug. What I think is not happening here is twofold, the virtual proxy analysis/generator is not climbing the inheritance tree to find the callthrough interface and the |
That worked well, thanks looking into this :) |
I just encountered the same issue, and it was difficult to track down the problem since one of the errors points to a generated file for the application class, instead of either the activity or the ActivityMenuCompat-implementing class. I would like to suggest linking to this issue in the Call-Through Events section here to save time for developers in the future: http://androidtransfuse.org/documentation.html#activity |
👍 @knutsoned, we should add this to the docs (or at least some wording to relfect this). And, one of the changes for the 0.3.0 needs to be better error reporting. |
I'd like to inject the matching transfuse activity in my menuController class like this:
The reason is that I need to call a function I defined in SearchActivity and that is supposed to stay there.
Currently above code yields the following error:
The text was updated successfully, but these errors were encountered: