Android Question Resumables and Activity_Create - Activity_Resume

RJB

Active Member
Licensed User
Longtime User
I thought I would put the "wait for" at the end of Activity_Create where the sub would be returning anyway. All of the code then runs before the Return at the wait for. However Activity_Resume then runs twice.
Is it safe to put a 'wait for' at the end of Activity_Resume (e.g. for runtime permissions) or will there be unexpected repercussions of doing that?
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
I've actually just put the "Activity_PermissionResult" into a separate sub to avoid the problem. Its a shame as the 'wait for' option looked much neater. Perhaps a modal wait for is the answer? :)
Now I need to check what is happening everywhere were I've use 'sleep(0)' to replace DoEvents.
 
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
I just went through the same thing (https://www.b4x.com/android/forum/threads/solved-run-time-permission-syncronization.88701/). What I ended up doing was moving the code from the Main activity to another activity and now use Main to get all the permissions squared away. I do a Check first and if a permission is missing, I put up a screen explaining the need for the permission and then call the "new" Main activity. Once the permissions are granted, the next time the app is run, it just drops through without a noticeable delay.

B4X:
Sub Process_Globals
   
    Public ExtStorage As Boolean = False
    Public ReadPhone As Boolean = False
   
End Sub

Sub Activity_Create(FirstTime As Boolean)

    ExtStorage = rp.Check(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    ReadPhone = rp.Check(rp.PERMISSION_READ_PHONE_STATE)
  
    If (ExtStorage And ReadPhone) Then
        StartActivity(GUI)
    Else
        Activity.LoadLayout("Setup")
      
        Dim Msg As String = _
            "Due to new security requirements from Google, you will be required to allow certain permissions. " _
            & "It is highly recommended that you accept these requests. Once accepted, you will not be asked again." & CRLF & CRLF
            
        If Not(ExtStorage) Then Msg = Msg & _
            "The photos, media, and files request is to allow downloading files to the SD card." & CRLF & CRLF
          
        If Not(ReadPhone) Then Msg = Msg & _
            "The make and manage phone calls request is to allow pausing the show when the phone rings. No outgoing " _
            & "calls or other phone access will be required."  & CRLF & CRLF
          
        Msg = Msg & _
            "Press the OK button to answer the prompts and start the app"
  
        txtMessage.Text = Msg
            
    End If
  
End Sub

Sub btnOK_Click
  
    GetPermissions
  
End Sub

Sub GetPermissions
  
    ExtStorage = rp.Check(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    If Not(ExtStorage) Then
        rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        ExtStorage = Result
    End If
  
    ReadPhone = rp.Check(rp.PERMISSION_READ_PHONE_STATE)
    If Not(ReadPhone) Then
        rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        ReadPhone = Result
    End If

    StartActivity(GUI)
  
End Sub
 
Last edited:
Upvote 0

RJB

Active Member
Licensed User
Longtime User
I've done something similar regarding explanation of the need for the permissions. Just asking without any explanation can be quite worrying to the user.
There does seem to be a problem with rp.check not working correctly first time after installation (i.e. when you really need it to work correctly), at least for Location permission, but I haven't gotten to the bottom of it yet.
 
Upvote 0
Top