I think I have things where they should be - I used the Camera sample code as the basis for this app. After the photo is saved locally to the SDcard I HTTP it up to my server. The Success Sub is here (I have added the Try/Catch statement to prevent the error from hanging the app) :
Code:
Sub hc1_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Log("hc1 Success: " & Response )
Log("hc1 Success: Timer1.Interval = " & timer1.Interval )
Response.Release
lblStatus.Text = "Image uploaded. Waiting on timer..."
're-enable the timer
Timer1.Enabled = True
btnTakePicture.Enabled = True
'show camera preview (was frozen whie we uploaded the previous image)
Try
Camera1.StartPreview
Catch
'Msgbox("Error in HTTP Success!", "Ooops")
End Try
Log("hc1 Success(END)")
End Sub
The app takes a photo every X seconds and uploads it to the server. Hence the timer stuff.
The error I get happens if I press the phone's Home button AFTER an upload has started. If you'll check the Designer logs below you will see that I pause the app, then the HTTP upload finishes (the log displays "sending message to waiting queue.") Then I re-run the app (from the icon on the phone) and I get the error.
The logs seem to show that the HTTP Success sub gets run before the Resume sub - and so the Camera1.StartPreview statement fails.
With the Try/Catch block that I just added all is now ok.
I'm not sure of the ordering as to when the Resume code should run - maybe all is as it should be. I guess I was expecting the Resume sub to kick in immediately I resumed the app, followed by the HTTP Success sub.
The second log below shows how it all works ok with the Try/Catch - but the HTTP message is still being processed before the Resume sub.
Any clarification on this would be much appreciated.
Thanks,
-Kim
(Observation: I display the contents of the HTTPResponse in the log entry. There seems to be a spelling mistake in the phrase "HTTPResponeWrapper":
anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper@4586c9
- not sure if it is of any cause for concern or not)
Log with the error:
...
Camera1_PictureTaken()
Camera1_PictureTaken(END)
** Activity (main) Pause, UserClosed = false ** <-- I pressed the Home button
sending message to waiting queue. <-- I'm assuming this is the HTTP request completing behind the scenes - the app is paused at this point
running waiting messages (1)
hc1 Success: anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper@4586c9c0v <-- I clicked the app icon to resume it
hc1 Success: Timer1.Interval = 20000 <-- NOTE the HTTP Success sub runs before the Resume sub
main_hc1_responsesuccess (java line: 502)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.CameraW.StartPreview(CameraW.java:101)
at com.britican.autocam.main._hc1_responsesuccess(main.java:502)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at anywheresoftware.b4a.BA$1.run(BA.java:210)
at anywheresoftware.b4a.BA.setActivityPaused(BA.java:263)
at com.britican.autocam.main$ResumeMessage.run(main.java:190)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
Log from the same process but with the Try/Catch:
...
Camera1_PictureTaken()
Camera1_PictureTaken(END)
** Activity (main) Pause, UserClosed = false ** <-- I pressed the Home button
sending message to waiting queue. <-- I'm assuming this is the HTTP request completing behind the scenes - the app is paused at this point
running waiting messages (1)
hc1 Success: anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper@4592aee0 <-- I clicked the app icon to resume it
hc1 Success: Timer1.Interval = 20000 <-- NOTE the HTTP Success sub runs before the Resume sub
hc1 Success(END) <-- The Try/Catch allows the HTTP Success sub to run to completion
** Activity (main) Resume ** <-- ...and now the Resume sub kicks in
Activity_Resume(): Timer1.Interval = 20000
Camera1_PictureTaken()
Camera1_PictureTaken(END)
...