Android Question Sub Activity_CreateMenu(Menu As ACMenu) when fired and how to prevent

peacemaker

Expert
Licensed User
Longtime User
HI, All

Sometimes there is error at this sub, if without delay the AppCompat activity is required to be closed.
Seems, the menu is not created yet or so.

When the menu creation starts ? How to control menu creation moment ?
 
Upvote 0
I don't like

Code: Copy
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
    if (processBA.subExists("activity_createmenu")) {
        processBA.raiseEvent2(null, true, "activity_createmenu", false, new de.amberhome.objects.appcompat.ACMenuWrapper(menu));
        return true;
    }
    else
        return false;
}

Not sure, but raiseEvent looks like asynchronous operation. So, when event happens "menu" (theoretically) can be absent.
Probably, better to use something like this:
Code: Copy
public boolean _onCreateOptionsMenu (android.view.Menu menu)
    { try { _activity_createmenu (new de.amberhome.objects.appcompat.ACMenuWrapper (menu)); return true; }
    catch (Exception e) { return false; } }
 
Upvote 0
How to prevent was answered, Don ?
Seems, this new sync Java sub is solving.... i'm testing
 
Last edited:
Upvote 0
The question in #1 is answered.

"Go and se a tutorial that DOES NOT solve the error" is not an answer.

better to use something like this:

This "suggestion" is ACTUALLY an option to solve the problem.

And another answer(Maybe not the best option), what I did it was just to enclose all the code with a TRY:

Code: Copy
Sub Activity_CreateMenu(Menu As ACMenu)
Try
    'Your code to add items here
    ToolBar.InitMenuListener
Catch
    Log("Activity_CreateMenu Error")
End Try

End Sub
 
Last edited:
Upvote 0
Back
Top