Hi!
I have searched and read tutorials but I couldn't find an answer to my question. I have problems to understand the correct use of "Wait For". I know, what it does. But I have no idea, how to write "clean apps" with this command for my case ...
I want to wait, until the Permission-Check has finished. Do_More_Things() should be executed, after AskForPermission() is completed. I don't want, that my app will continue before that.
Now, Activity_Create starts and calls AskForPermission. AskForPermission runs and come to "Wait For Activity_PermissionResult" and exits AskForPermission (because it waits now). So we are back in Activity_Create and come to "Wait For Sub_is_finished". Because this event didn't happen, the Sub is also exited and the app is continued (with Activity_Resume). But I want to wait (app should be blocked because the app is useless without the asked permission).
Is this the recommended solution? I have no problem with this, but I would like to know, if this is the recommend way to stop execution of an app, until some things were finished before? Does it cost much battery (because the Do/Loop repeats and repeats and repeats very often and I think, this cost CPU power and drains the battery)?
Thank you very much!!
Wolfgang
I have searched and read tutorials but I couldn't find an answer to my question. I have problems to understand the correct use of "Wait For". I know, what it does. But I have no idea, how to write "clean apps" with this command for my case ...
This is my program (extremly shortened)::
Sub AskForPermission
rp.CheckAndRequest (rp.PERMISSION_READ_PHONE_STATE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
End Sub
Sub Activity_Create(FirstTime As Boolean
If FirstTime = True Then
AskForPermission
End If
Do_More_Things
End Sub
I want to wait, until the Permission-Check has finished. Do_More_Things() should be executed, after AskForPermission() is completed. I don't want, that my app will continue before that.
So, now I can do the following::
Sub AskForPermission
rp.CheckAndRequest (rp.PERMISSION_READ_PHONE_STATE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
CallSubDelayed(Me, "Sub_is_finished")
End Sub
Sub Activity_Create(FirstTime As Boolean
If FirstTime = True Then
AskForPermission
Wait For Sub_is_finished
End If
Do_More_Things
End Sub
Now, Activity_Create starts and calls AskForPermission. AskForPermission runs and come to "Wait For Activity_PermissionResult" and exits AskForPermission (because it waits now). So we are back in Activity_Create and come to "Wait For Sub_is_finished". Because this event didn't happen, the Sub is also exited and the app is continued (with Activity_Resume). But I want to wait (app should be blocked because the app is useless without the asked permission).
I know a solution::
Sub AskForPermission
rp.CheckAndRequest (rp.PERMISSION_READ_PHONE_STATE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
bol_Sub_is_finished = True
End Sub
Sub Activity_Create(FirstTime As Boolean
If FirstTime = True Then
AskForPermission
Do
If bol_Sub_is_finished = True Then Exit
DoEvents
Loop
End If
Do_More_Things
End Sub
Is this the recommended solution? I have no problem with this, but I would like to know, if this is the recommend way to stop execution of an app, until some things were finished before? Does it cost much battery (because the Do/Loop repeats and repeats and repeats very often and I think, this cost CPU power and drains the battery)?
Thank you very much!!
Wolfgang