Solution
The problem is with the image:
Sub Process_Globals
Public Image As Bitmap 'public image
Private SQL1 As SQL 'private sql object
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Image = LoadBitmap(File.DirAssets, "Image.jpg")
SQL1.Initialize(File.DirInternal, "1.db", True)
End If
End Sub
The reason that this image is public is that we plan to use it from other activities.
For example:
'Activity2
Sub Activity_Create(FirstTime As Boolean)
Activity.SetBackgroundImage (Main.Image)
End Sub
During development everything will look fine. The application will always start from the main activity and the image will live as long as the process lives.
However it will eventually fail when it is installed on the user device.
The user will press on the home key when the second activity is visible. The process will move to the background.
At some point the OS will kill the process as it is in the background.
Later when the user returns to the app the process
will start from the second activity.
Main activity was not created yet so its Activity_Create wasn't executed. This means that the image is not initialized at that point.
You can see it during development with this developer setting:
Run your app in Release mode, switch to the second activity, press on home and start a different app. Return to your app and in most cases it will start from the second activity directly.
To solve this issue you can add a code module that holds all the public resources:
Sub Process_Globals
Public Image As Bitmap
Private alreadyInitialized As Boolean
End Sub
Public Sub Init
If alreadyInitialized = False Then
Image = LoadBitmap(File.DirAssets, "Image.png")
'all other resources as well
alreadyInitialized = True
End If
End Sub
Now you should call this Init sub from Activity_Create (and Service_Create) of all activities and services.
Related quiz:
https://www.b4x.com/android/forum/threads/37899/#content