You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
The generated code is wrong when extending activities annotated with @OptionsMenu #473
I have the following problem. I have two AA annotated activities. Activity A has an @optionsmenu extension. I want activity B to extend from A but have another @optionsmenu. Doing this I end up with a compilation error in my generated code, since it generates two public boolean onCreateOptionsMenu(Menu menu) which leads to a duplicate method error...
Is there any idea how i can fix it other than removing the annotation from activity A and put it to all its child classes except B?
Now, when multiple @OptionsMenu are processed from the class hierarchy, only one method is created, and this method inflate all the declared menu from super classes annotations.
I am having the same issue, although I can't even inherit my Activity because it's final. On this page, it says "we favor composition over inheritance" and I'd love to know if there's a way to just inject the OptionsMenu functionality into all my Activities.
I think keeping OptionMenu stuff in a separate EBean class would be cool, because then you could just inject several of them into your Activity and it would combine them for you. This would also make it easy to add a single menu item to the global application menu only on certain activities (for instance, a Share button). Do you think this is possible?
Sorry for the late answer, i'm currently switching to a new job...
Actually, there is now way to define application-wide options menu.
The main issue I see with your proposal is how to deal with incremental compilation. In fact AA does not keep any state between each compilation, so when OptionsMenuActivity is compiled, nothing is known about MyOptionsMenu and the right code cannot be generated.
Activity
mathieuboniface commentedon Jan 26, 2013
I've just provided a fix on that issue.
Now, when multiple
@OptionsMenuare processed from the class hierarchy, only one method is created, and this method inflate all the declared menu from super classes annotations.Example :
Will produce the following code :
@charlie
To resolve your issue, you can try the latest snapshot from here : https://oss.sonatype.org/content/repositories/snapshots/org/androidannotations/androidannotations-bundle/3.0-SNAPSHOT/
We could enhance AA flexibility by providing a way to override
@OptionsMenudeclared from super classes. Any thoughts appreciated !Example :
Should produce the following code :
odbol commentedon Feb 5, 2013
I am having the same issue, although I can't even inherit my Activity because it's final. On this page, it says "we favor composition over inheritance" and I'd love to know if there's a way to just inject the OptionsMenu functionality into all my Activities.
I think keeping OptionMenu stuff in a separate EBean class would be cool, because then you could just inject several of them into your Activity and it would combine them for you. This would also make it easy to add a single menu item to the global application menu only on certain activities (for instance, a Share button). Do you think this is possible?
odbol commentedon Feb 6, 2013
To expand on your example:
And then you would inject it into your Activity like this:
mathieuboniface commentedon Feb 23, 2013
Hi @odbol,
Sorry for the late answer, i'm currently switching to a new job...
Actually, there is now way to define application-wide options menu.
The main issue I see with your proposal is how to deal with incremental compilation. In fact AA does not keep any state between each compilation, so when
OptionsMenuActivityis compiled, nothing is known aboutMyOptionsMenuand the right code cannot be generated.DayS commentedon Jan 20, 2014
All of this should (but the override option) be fixed now.