Android Question Menu is not working

MrKim

Well-Known Member
Licensed User
Longtime User
I built a two item menu on a new Nexus 7. It worked Fine.
I tried it on a tablet with a slightly older version of Android. An Insignia running 4.1.1.
The menu does not open. I have stepped through the code with the debugger and
Activity.OpenMenu is definitely run, but nothing happens. The code to create the menu also runs.

Here is the relevant code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim InterCon As ServerSocket
  If FirstTime Then
          If Not(File.Exists(File.DirInternal, "PartsAndTime.db")) Then
            SQL1.Initialize(File.DirInternal, "PartsAndTime.db", True)
            SQL1.ExecNonQuery("CREATE TABLE EmpInfoLookups (Emp_Num TEXT PRIMARY KEY NOT NULL, Emp_FirstName TEXT, Emp_LastName TEXT, Emp_AllowEdits INT, Emp_Rate TEXT);")
            SQL1.ExecNonQuery("CREATE TABLE ReleaseLookups  (JobRel TEXT, Jr_JobNum TEXT, Jr_ReleaseNum TEXT, StartDate TEXT, FirstDueDate TEXT, FinishDate TEXT, Jr_StartQty Int, Jr_MinDueQty Int, Jr_RejectQty Int, Jr_Complete TEXT, PictureName TEXT);")
            SQL1.ExecNonQuery("CREATE UNIQUE INDEX JobRel on ReleaseLookups  (JobRel );")
            SQL1.ExecNonQuery("CREATE TABLE OPsLookups (Os_ID Int, Os_JobNum TEXT, Os_ReleaseNum  TEXT, Os_SeqNum Int, Os_WCCode TEXT, Os_Description TEXT, Os_QtyTodate Int, Os_Note TEXT, Os_Status TEXT, Os_RunTime REAL, Os_OMLink Int, Wc_Cell Text, Wc_TypeCode TEXT);")
            SQL1.ExecNonQuery("CREATE UNIQUE INDEX JobRelSeq on OPsLookups (Os_ID);")
            SQL1.ExecNonQuery("CREATE TABLE JobsLookups (Jb_Job_Num TEXT PRIMARY KEY Not Null, Jb_Part_Num TEXT, Jb_Part_Rev TEXT);")
        Else  
            SQL1.Initialize(File.DirInternal, "PartsAndTime.db", False)
        End If
    End If
    Activity.LoadLayout("Main")
    Activity.AddMenuItem("Setup", "IPISetup")
    Activity.AddMenuItem("Close Program", "IPIClose")
    UpdateJobCycleBtn.Tag = False
    UpdatePMCycleBtn.Tag = False
    Dim InterCon As ServerSocket
    InterCon.Initialize(0, "")
    MainIPAddr = InterCon.GetMyIP
 
    InterCon.Initialize(0, "")
    MainIPAddr = InterCon.GetMyIP
End Sub
 
Sub Activity_KeyPress(KeyCode As Int) As Boolean
 
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        If SCV.IsInitialized Then
            If SCV.Visible Then
                SCV.Visible=False
                SCV.RemoveView
            Else
                Activity.OpenMenu
            End If
        Else
            Activity.OpenMenu
        End If
        Return True
    End If
 
End Sub

Any ideas greatly appreciated
 

MrKim

Well-Known Member
Licensed User
Longtime User
OK after a little research. I don't have a title (#IncludeTitle: False) if I include the title I get a menu on the title bar and the trap of the BACK Key works and opens the menu. Without a title bar there is no menu on this device (or OS version?). As I mentioned on another tablet it works fine.
I don't want a title bar. Don't want to give up the space.
Any ideas for workarounds.

Also, I am curious how prevalent this problem is. The code for a simple menu is below. If anyone would like to test on their device and report.
I have included a simple program it has no title bar, and the back key should open a menu to close the program. There is also a button to close if that fails.

As an aside, on the Nexus 7 with no title, the menu opened in the lower right corner. Any way to control that?
 

Attachments

  • MenuTest.zip
    6.9 KB · Views: 223
Upvote 0

NJDude

Expert
Licensed User
Longtime User
There's no problem, first of all, Google deprecated the use of the MENU button and replaced it with the ActionBar, second, on SDK >=14 if you hide the title you won't see the "soft" menu button, on older versions the menu button will always display, so, if you want to be consistent on any version of Android don't use the menu button but the Action bar.

Devices such as the Nexus 7 and other phones and tabs that do not have hardware menu buttons will behave this way (3 little dots, but only if you target SDK < 14)

I hope that clear things up.
 
Upvote 0
Top