@SimonatMSL,
I think that you have 2 problems
1. the calling sub
sub domywork
PermissionTake1
'continue with other code, which crashes, because the permissions have not been set.
end sub
The issue is that PermissionTake1 returns to domywork as soon as the first Wait For is reached. This is expected behaviour of using Wait for
You need to do something like:
sub domywork
Wait for (PermissionTake1) complete (ret as object) ' or boolean or whatever
'continue with other code, this will now wait until permissionTake1 completes
end sub
2. ExitApplication
I don't believe that exitapplication closes the app
immediately. I think that if there are messages on the queue these are processed.
So the code above would still not work properly since the app does not actually exit until control is returned to the OS.
My recommendation is this:
sub domywork
PermissionTake2
' do nothing else here return to OS
end sub
sub continuewithapp
' this is where you can get on and do any work, knowing that all the permissions succeeded
end sub
Sub PermissionsTake2 as resumeablesub
Log ("Checking PERMISSION_WRITE_EXTERNAL_STORAGE")
Wait For (MyPermission(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)) Complete (Result As Boolean)
Log ("Finished checking PERMISSION_WRITE_EXTERNAL_STORAGE")
If Result = False Then
ToastMessageShow("Unable to set up PERMISSION_WRITE_EXTERNAL_STORAGE", True)
ExitApplication
return false
End If
Log ("Checking PERMISSION_ACCESS_COARSE_LOCATION")
Wait For (MyPermission(rp.PERMISSION_ACCESS_COARSE_LOCATION)) Complete (Result As Boolean)
Log ("Finished checking PERMISSION_ACCESS_COARSE_LOCATION")
If Result = False Then
ToastMessageShow("Unable to set up PERMISSION_ACCESS_COARSE_LOCATION", True)
ExitApplication
return false
End If
Log ("Checking PERMISSION_ACCESS_FINE_LOCATION")
Wait For (MyPermission(rp.PERMISSION_ACCESS_FINE_LOCATION)) Complete (Result As Boolean)
Log ("Finished checking PERMISSION_ACCESS_FINE_LOCATION")
If Result = False Then
ToastMessageShow("Unable to set up PERMISSION_ACCESS_FINE_LOCATION", True)
ExitApplication
return false
End If
' Let the app know it can continue
callsub(me,"continuewithapp")
return true
End Sub
I haven't checked this in the IDE.I have just typed it in here. But I think this should solve your problem. You don't actually need to return a boolean.