Android Question endless loop in check permission

Discussion in 'Android Questions' started by dcoun, Jul 11, 2018.

Thread Status:
Not open for further replies.
  1. dcoun

    dcoun Member Licensed User

    In the main activity I have a sub that it is call by a resumable sub initiated by the activity_resume
    It runs the command Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_EXTERNAL_STORAGE)
    in the Sub Activity_PermissionResult I have only a Log("perm: "&Result)
    Any idea why I never see the permission window and I can see only the following in the logs


    perm: false
    ** Activity (main) Resume **
    main resume
    true
    ** Activity (main) Pause, UserClosed = false **
    sending message to waiting queue (activity_permissionresult)
    running waiting messages (1)
    perm: false
    ** Activity (main) Resume **
    main resume
    true
    ** Activity (main) Pause, UserClosed = false **
    sending message to waiting queue (activity_permissionresult)
    running waiting messages (1)
    perm: false
    ** Activity (main) Resume **
    main resume
    true
    ** Activity (main) Pause, UserClosed = false **
    sending message to waiting queue (activity_permissionresult)
    running waiting messages (1)
    perm: false
    ** Activity (main) Resume **
    main resume
    true
    ** Activity (main) Pause, UserClosed = false **
    sending message to waiting queue (activity_permissionresult)
    ** Activity (main) Pause, UserClosed = false **
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is a mistake to have an Activity_PermissionResult sub. You should use Wait For. It is simpler.

    It is hard to say anything else as you haven't posted the code.
     
    dcoun likes this.
  3. dcoun

    dcoun Member Licensed User

    Change it to not have any resumable subs.... The same results. Code follows:
    Code:
    Sub Activity_Resume
    Log("main resume")
    GetReady
    End Sub


    Sub Activity_PermissionResult (Permission As String, Result As Boolean)
        
    Log("perm: "&Result)
    End Sub

    Sub GetReady
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_EXTERNAL_STORAGE)
    End Sub
     
  4. dcoun

    dcoun Member Licensed User

    With the following code I get:
    Code:
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_EXTERNAL_STORAGE)
        
    Wait For PermissionResult (Permission As String, Result As Boolean)
    ** Service (starter) Start **
    ** Activity (main) Create, isFirst = true **
    maincont
    ** Activity (main) Resume **
    main resume
    true
    *** Service (httputils2service) Create ***
    ** Service (httputils2service) Start **
    ** Activity (main) Pause, UserClosed = false **
    sending message to waiting queue (activity_permissionresult)
    running waiting messages (1)
    main$ResumeMessagerun (java line: 306)
    java.lang.Exception: Sub activity_permissionresult was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA$2.run(BA.java:365)
    at anywheresoftware.b4a.BA.setActivityPaused(BA.java:437)
    at medsite.mypatients.main$ResumeMessage.run(main.java:306)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    I recommend you to watch the video tutorial. There are many mistakes in the code you posted.
     
  6. dcoun

    dcoun Member Licensed User

    I corrected the Wait for but I can not find the "many mistakes"
    Thank you in advance
     
  7. dcoun

    dcoun Member Licensed User

    The code now is:
    Code:
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_EXTERNAL_STORAGE)
        
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    In the manifest I entered
    AddPermission(android.permission.PERMISSION_READ_EXTERNAL_STORAGE)

    and the problem continues
    I can not find anything else in the tutorial

    ** Activity (main) Resume **
    main resume
    true
    ** Activity (main) Pause, UserClosed = false **
    sending message to waiting queue (activity_permissionresult)
    running waiting messages (1)
    perm: false
    ** Activity (main) Resume **
    main resume
    true
    ** Activity (main) Pause, UserClosed = false **
    sending message to waiting queue (activity_permissionresult)
    running waiting messages (1)
    perm: false
    ** Activity (main) Resume **
    main resume
    true
    ** Activity (main) Pause, UserClosed = false **
    sending message to waiting queue (activity_permissionresult)
    running waiting messages (1)
    perm: false
    ** Activity (main) Resume **
    main resume
    true
    ** Activity (main) Pause, UserClosed = true **
     
  8. dcoun

    dcoun Member Licensed User

    I think this thread should be moved to bugs:
    Create a new project, select library runtimepermissions
    Change only the following code:
    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim rr As RuntimePermissions

    End Sub

    Sub Activity_Resume
            rr.CheckAndRequest(rr.PERMISSION_READ_EXTERNAL_STORAGE)
            
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
            
    Log("perm: "&Result)

    End Sub
    If I run it, it shows:

    To be honest I can not understand why this happen
     
  9. Erel

    Erel Administrator Staff Member Licensed User

Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice