App crashes when an image is set as an activity background.

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Can you tell me how to stop my app from crashing after an image is set as an activity background?

This is what happens.

The app sets the background image for the main activity:

B4X:
Sub Activity_Create(FirstTime As Boolean)

   ' Open up the maintenance window.
   '--------------------------------
   Activity.LoadLayout("Maintenance")
   Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "grocerybig.jpg"))
   
End Sub

The user clicks a button to call another activity:

B4X:
Sub ButtonMaintenance_Click
   StartActivity(Maintenance)   
End Sub

That activity also sets the background image with the same coding.

From that activity the user clicks on the Stores button to load that activity and that activity also does the same thing with an image.

B4X:
Sub ButtonStores_Click
   StartActivity(MaintenanceStores)   
End Sub

The app now crashes on this statement after the layout is loaded:

B4X:
   Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "grocerybig.jpg"))

Is there some sort of setting I need to set?

The app also crashes if I start the app on the main activity and exit it with:

B4X:
Sub ButtonClose_Click
   Activity.Finish
End Sub

and run the app from the phone apps screen. If I comment out the setting of the background image on all activities, then no crash occurs.

Thanks.
 

rleiman

Well-Known Member
Licensed User
Longtime User
I just tried setting the image on a panel background and the same thing happened if the user exits the app and immediately runs the app again. If I the user waits a short while before running the app again, it will load.

Looks like I need to clear out some stuff right before exiting the app.

Can you tell me the coding needed to get this working?

Thanks.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
I'm experiencing a similar scenario.

I set the backgroud image using the Designer , and going from an activity to another that have the same image set as backgroud I got a crash.

The problem appear more frequently on Android 4.3 JB.
I'll will verify the solution suggested...
 
Last edited:
Upvote 0
Top