Android Question How to let "CheckAndRequest" run before Starter service starts?


Licensed User
Longtime User
This is my first post,Thank you for your help.
When the app is about to run,
it will crash because there is no storage permission

in the main
Sub Activity_Create(FirstTime As Boolean)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("..........", True )
    End If

End Sub

in the starter.bas

Sub Service_Create   
 Dim dir As String
        dir = File.DirDefaultExternal
        If  Not (File.Exists( dir, "sd.db")  ) Then
            File.Copy(File.DirAssets, "sd.jpg",  dir, "sd.db" )
        End If
        SQL1.Initialize( dir, "sd.db", True)
End sub
Last edited:


B4X founder
Staff member
Licensed User
Longtime User
Welcome to the forum!

There are several mistakes here.

1. Service_Create of the starter service is run before the permission is requested.
2. You don't need a permission at all. Watch the runtime permissions video tutorial and it will be clear.
You need to use RuntimePermissions.GetSafeDirDefaultExternal.

3. I would have used File.DirInternal instead. Save yourself crashes that will happen when the secondary storage is not available.

4. Use DBUtils. It will help you:
There is a method named CopyDBFromAssets which you can use.
Upvote 0