An extension can register for 'onCreateOptionsMenu'. In class 'Form' method 'onCreateOptionsMenu' calls the method 'onCreateOptionsMenu' for all registered components. In class 'ReplForm' method 'onCreateOptionsMenu' is overwritten and does not call the registered components.
Is there a special reason for doing so? If not, I ask you to call the registered components in 'replForm' too. This helps to test apps in the companion.
Hmm it looks like it the ReplForm is properly calling the super function here, so the registered extensions should be able to create their menu options. Is this not the behavior you're seeing?
Best =)
--Beka
1 Like
Thanks for the hint. I overlooked the call to super.
I did a new test with a little more precision. As expected, the compiled app has two menu items ('Stop ..' and 'About ..'). Running the project in the companion there are three menu items ('Stop..' and 'About..' added by Form and 'Settings' added by ReplForm). That means 'onCreateOptionsMenu' is called in both cases. But the extensions 'onCreateOptionsMenu' callback is only called with the compiled apk file.
The test can be downloaded here https://ullisroboterseite.de/_forDownload/MenuTest.zip. The zip file contains:
- The source of a minimalist extension. It registers for 'onCreateOptionsMenu' in the constructor and writes to the Android Log (level d, tag "MENU") when 'onCreateOptionsMenu' is called.
- Screenshots of the test (companion and apk)
- The compiled extension (.aix)
- The project file (.aia)
- The compiled app (.apk)
I hope this helps analyzing the problem.
Kind regards
Ulrich
When are you first opening the menu? onCreateOptionsMenu
is only called the first time the menu is opened (per the Android docs). If you want to change items on the menu at runtime it is more appropriate to do it in onPrepareOptionsMenu
.