Android Question Disappearing menu in target SDK 24+

RichardN

Well-Known Member
Licensed User
Longtime User
I just updated an existing app to targetSdkVersion="27" with permission for "PERMISSION_WRITE_EXTERNAL_STORAGE" and it all seems to work as expected with one exception...

The single Activity, single screen app has 3 menu options added in the normal way but the 3 dots in the title bar have disappeared rendering the menu inaccessible. If I return the target SDK to 22 commenting our the permissions code it reappears.

What am I missing?
 
Last edited:

MarkusR

Well-Known Member
Licensed User
Longtime User
does this device have a menu icon at bottom bar then or have it a hardware menu key?
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Markus... The target device is a Samsung S9+ (SM-G965F) running Android 8.0.0. It does not have a hard or soft menu key.

Mahares... Personally I have not yet experienced any incompatibilities with targetSDK27. I have tried 26 and 24 - same result. Like I said above, if I drop the targetSDK to 22 the RTP code has to be removed to function but the 3-dots-menu with functionality returns.
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
I can't find it in any documentation.... but I suspect the simple menu methodology is not supported after SDK 22.

If that is the case what is the easiest solution for replacing a simple menu?
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
can u reproduce it in a simple new project and attach it here?
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
By a process of trial & error I have isolated the problem and it is associated with the position of 'Wait For' in the Activity_Create Sub. As a result I have reviewed the 'Resumable Subs' tutorial but I still do not understand the menu behaviour.

In this first example the menu does not appear....
B4X:
Sub Activity_Create(FirstTime As Boolean)
    
    'In this example the Android manifest is the default version.
    'The RTP code functions correctly, the SQL database initialises correctly
    'and the layout is loaded and displayed without any errors.  However but the 3 menu dots
    'are absent And there Is NO menu funtionality.
    
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult(Permission As String,Result As Boolean)
        
    If Result = False Then
        'Some user dialogue here
    End If
        
    If FirstTime Then
        SQL.Initialize(File.DirInternal, "MySQLite.db",True)
    End If
    
    Activity.LoadLayout("1")
    Activity.AddMenuItem("First Choice","mnuFirstChoice")
    Activity.AddMenuItem("Second Choice","mnuSecondChoice")
    Activity.AddMenuItem("Third Choice","mnuThirdChoice")

End Sub

In this second example the code is re-ordered moving the RTP code to the end of the module (moving it out of the module works equally well).
B4X:
Sub Activity_Create(FirstTime As Boolean)
    
    'Once again the Android manifest is the default version.
    'The RTP code is now moved to the end of the module  This time the activity, layout
    'and the menu functions work correctly. Why?
        
    If FirstTime Then
        SQL.Initialize(File.DirInternal, "MySQLite.db",True)
    End If
    
    Activity.LoadLayout("1")
    Activity.AddMenuItem("First Choice","mnuFirstChoice")
    Activity.AddMenuItem("Second Choice","mnuSecondChoice")
    Activity.AddMenuItem("Third Choice","mnuThirdChoice")

    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult(Permission As String,Result As Boolean)
        
    If Result = False Then
        'Some user dialogue here
    End If
    
End Sub

Having refreshed on resumable subs I still have no idea why one works and the other does not ???
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Having refreshed on resumable subs I still have no idea why one works and the other does not ???
1. Rule number one when working with resumable subs:
Sleep and Wait For are equivalent to Return from the calling code perspective.

2. The menu must be created before returning from Activity_Create.

3. This doesn't happen when you use Wait For before adding the menu items.
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
This doesn't happen when you use Wait For before adding the menu items.

That is my problem. It is difficult to understand because in the first case the code items of SQL.Initialise and Activity.LoadLayout are also after the Wait For clause but unlike Activity.AddMenuItem are executed without problem......?

There will be cases where checking of a RTP early in Activity_Create is required to facilitate other code execution so using Wait For in Activity_Create does not appear to be good practice. I will be using a separate Sub in future.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
That is my problem. It is difficult to understand because in the first case the code items of SQL.Initialise and Activity.LoadLayout are also after the Wait For clause but unlike Activity.AddMenuItem are executed without problem......?
All the code is executed.

However the menus must be created before the code returns from Activity_Create. This doesn't happen if you call Wait For before adding the menu items.

Watch the resumable subs video tutorial. It explains the code flow.

https://www.b4x.com/etp.html
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
SQL.Initialize(File.DirInternal, "MySQLite.db",True)
Why are you requesting permission when the database is stored in File.DirInternal. My understanding of runtime permissions is that its entire check and request code is not required if you use File.DirInternal, unless I have a poor understanding of the entire concept.
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
The RTP was being requested for another purpose later on in the program. It semed to make sense to execute the check with the user when the program opened rather than at some other point later.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The RTP was being requested for another purpose later on in the program.
If you say so!!
However, you should have pointed that out in your first post and in post #9. Someone searching for help on Runtime Permissions and viewing your post #9 might get confused and thinks that it is required for FileDirInternal, which is a false assumption.
 
Upvote 0
Top