AddMenuItem behaviour in 2.7x

nwhitfield

Active Member
Licensed User
Longtime User
I've been working on my app for a while, using 2.52, and in the main module, this code is included in Activity_Create:

B4X:
If BLUFtools.initLanguage(StateManager.GetSetting2("language",BLUFtools.getDeviceLanguage)) = False Then
   BLUFtools.initLanguage("en")
End If

Activity.AddMenuItem(BLUFtools.BLUFstrings.Get("M_logout"),"BLUFlogout")
Activity.AddMenuItem(BLUFtools.BLUFstrings.Get("M_notify"),"NotifyOFF")
Activity.AddMenuItem(BLUFtools.BLUFstrings.Get("M_settings"),"BLUFsettings"
Activity.AddMenuItem(BLUFtools.BLUFstrings.Get("T_update"),"profileUpdate")

(BLUFtools is a library that has various things, including loading all the text strings into an array)

This was all working fine; and it continues to work fine on my Galaxy Nexus with stock Android after updating to 2.71
As you'd expect, the overflow menu option is at the right of the menu bar, and tapping it reveals the appropriate choices.

However, I've just had someone try to install the app on a Galaxy S3, and he doesn't get a menu. The same has been reported by a user on an Xperia Mini, with Android 2.3.4.

I've tried an experiment with the S3 user, changing those calls to

B4X:
Activity.AddMenuItem3(BLUFtools.BLUFstrings.Get("M_logout"),"BLUFlogout",null,true)

And the result, in a screenshot he sent me, was that the first two items appear in the action bar, but there's no overflow to allow access to the others. And the Xperia mini user is still without any way of accessing the options on the menu at all.

The Galaxy screenshot confirms that the text strings are being loaded ok, so that's not the issue. It's just that the menu is no longer appearing.

I can code round this, of course, adding a button on screen, but it does seem a little peculiar.

SDK levels referenced in the manifest are:

B4X:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>

I've certainly not changed that myself.
 

Attachments

  • GS3menu.png
    GS3menu.png
    37.1 KB · Views: 291

nwhitfield

Active Member
Licensed User
Longtime User
Sorry if I wasn't clear enough... the overriding issue is not whether or not the three dots appear - I tried using the Action Bar as an alternative for the S3 user, and to verify the text strings are being correctly loaded, in case that was the root cause.

The problem is that on both the devices in question, the S3 and the Xperia Mini, the users are reporting that the device menu button has no action AT ALL.

Whether I use AddMenuItem or AddMenuItem3, the result is options that are inaccessible to users on those two devices, because pressing the menu button does not display anything.

On the three devices I have here (HTC One S, Nexus 7 and Google Nexus) the menu works as expected.

Is there some change in 2.7x that might cause this? I certainly haven't altered my Activity_KeyPress routine (which only checks for the Back key in any event), and the version of the app built using 2.5x had working menus.
 
Upvote 0

beacon

Member
Licensed User
Longtime User
Hi again.

I posted earlier today with exactly the same issue. Recompiled apps put to a Galaxy Tab and a Galaxy Note show no items when the menu key is pressed. Apologies, I cannot find that post now. However I tried Erel's follow-up suggestion to test.......

Sub Process_Globals
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.AddMenuItem("test", "test")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

That works fine.

However, I can now reproduce the no-show problem when I include

'Sub Activity_KeyPress (KeyCode As Int) As Boolean
'Anycode
End Sub

This appears to be trapping the menu-key call, and so no menu bar items are raised. (I am still looking for a cure.)

Does this help?

David

:sign0104:
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
By Jove, I think you've got it.

Of course, on my Nexus devices, there's no menu key, so you get the three dots on the menu bar, which if course works.

But on devices with one, a mistake in Activity_KeyPress not returning False when the menu key is pressed means the key is consumed.
 
Upvote 0

beacon

Member
Licensed User
Longtime User
This code works for me.

Sub Activity_KeyPress (KeyCode As Int) As Boolean
Dim Res As Int
If KeyCode = KeyCodes.KEYCODE_BACK Then
Res = Msgbox2("Do you want to exit?", "AppName", "Yes", "", "No", LoadBitmap(File.DirAssets , "AppPicture.png"))
If Res = DialogResponse.POSITIVE Then
Activity.Finish
Return False
Else
Return True
End If
Else
Return False
End If
End Sub

The new compiler is more exacting in its demands on our code - which is a good thing of course!

David.

:sign0104:
 
Upvote 0
Top