Ok, what you have looks ok. However, you have a main activity - but no UI code. So this looks like some kind of threading issue.
If you JUST launch what you have (debug mode), then we see this:
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
So, the startup code is running multiple times (that explains your "lock" error. The code not finished the first time - and it is being fired again!
I did not get a lock error, but I get a cursor error not initilized.
So when I run this I get:
Error occurred on line: 55 (Main)
java.lang.RuntimeException: Object should first be initialized (Cursor).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.sql.SQL$CursorWrapper.getRowCount(SQL.java:335)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.sql.main.afterFirstLayout(main.java:104)
at b4a.sql.main.access$000(main.java:17)
at b4a.sql.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
(the 55 might be off a few lines - I had put in a few extra "log" to spit out the row count.
So, the cursor seems to be even going out of scope!!! NONE of how this was behaving was making any sense at all!
I would create a layout - place a single button on it to call your routine that does the connect code + sql you have.
Even if I JUST add a layout - with a button - but it does nothing?
the code runs fine.
so try:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
If FirstTime Then
ConnectDatabases
End If
End Sub
Also note the "first time" check above.
So, starting that main without any kind of "UI", it seems the Android OS tosses out this "stray cat" routine - it will get restarted multiple times.
(that multiple times will explain the locking issue).
Have main load some kind of UI - that alone seems to fix this.
Better yet, is have a button call + run your Connect databases sub.
Or if you want/have no UI for quick testing? Then move all your code to the starter service if you just testing.
I ALWAYS thought that the starter service would finish before the "main" activity service starts. However, it can/will be fired multiple times - and it seems even several times without any kind of UI. And then it goes out of scope (again, due to no UI - I am betting some Android OS optomzing does this - hey - no UI - we going to stop that activity!!!).
So, if you wish to leave your code in "main", then load a layout with a single/simple button that runs this code.
I found your code runs fine if you load a layout. (and even without a button to call the code). But, for this testing, call the connect data stuff from a simple button would be the best bet here.
A few more tips:
Surprising the sample is set to release???? - it should be debug.
So, put it back to debug- and and do a tools->clean RIGHT after you switch it to debug before you try it.
I would also re-boot the actual device, since with those multiple threads running, the files get messed up and are locked.
So, if you not going to "wait" for any UI and a user hitting a button, them simply move all of your code to the starter service for testing.
And the "firstime" check is also a good idea.
However, your sql, and the code you have does look ok, and does run fine for me as long as I load a layout.
I did not try, but moving all your sample code to the starter service module also likely would have worked.
Regards,
Albert D. Kallal
Edmonton, Alberta Canada