Android Question Activity background image not loading

Azhar

Active Member
Licensed User
Longtime User
Hi

I have an activity whereby the user can select different activity background images. There are six .png files to choose from - all same image size, formats etc just different colours.
Within the customise form in Designer, if I exclusively set the background bitmapDrawable image from any of the six loaded files they all appear when Designer is in WYSIWYG Connection mode - no problems. The file is not corrupt as I can reload it into GIMP and it views in Microsoft Photos etc.
But when the application runs in Debug Mode, one image file 'does not exist'. The file is there, in the correct directory, there's no mismatch in filename or extension etc.
I don't know how to test further as I think the 'file does not exist' test error return is ambiguous in this regard and could therefore actually be another reason as to why it cannot be loaded.

I save and run my work from directories within OneDrive (Cloud based) so I can work on two different PC's at separate locations and everything is synced and ready to go) - The IDE did experience some Auto Save problems. I've always worked this way.

I have no idea on how to test further beyond the 'If file.exists(file.DirAssets,"{filename.png}) method to get a hint of what is going on.

The .png image sizes are all less than 3,440KB in size. Is there a limit to how many files can be loaded into the Application>Files directory or something?

Thanks
 

mangojack

Expert
Licensed User
Longtime User
But when the application runs in Debug Mode, one image file 'does not exist'.

Is it always the 'same' image ? maybe a small example project with the exact same images included might help ...
Or at least some code showing how you are loading the images ...


The .png image sizes are all less than 3,440KB in size. Is there a limit to how many files can be loaded into the Application>Files directory or something?

Hopefully they are much smaller than this. I'm sure there is no limit to number of files ... but obviously image size , number and how they are
loaded / displayed could eventually become a factor .. ie: Out Of Memory
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
have you double-checked case sensitivity?
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
I've triple checked everything. I also converted them all to JPEGs and that reduced the file sizes to 1/3 of the original. That didn't work either as the IDE couldn't find any of those files although they are all in the assets folder etc and display when connected to Designer's WYSIWYG.

But after I did a full Release compile, it worked! I could see all the different background graphics files change through their colours upon user selection. But after that, a run in Debug mode I get 'file does not exist again.

It is all so odd. And I'm beginning to think that it is a problem working live from a cloud directory (OneDrive).

Thanks




B4X:
Sub spBkgColour_ItemClick (Position As Int, Value As Object)
    Dim strValue As String
    Dim bd As BitmapDrawable
    
    Log("spBkgColour Position is :" & Position & " and Value is " & Value)
    
    If Value = "Black" Then strValue = "1440x2560BLA.jpg"
    If Value = "Blue" Then strValue = "1440x2560BLU.jpg"
    If Value = "Green" Then strValue = "1440x2560GRE.jpg"
    If Value = "Orange" Then strValue = "1440x2560ORA.jpg"
    If Value = "Red" Then strValue = "1440x2560RXD.jpg"
    If Value = "Light Blue Plain" Then strValue = "1440x2560BUP.jpg"

    Main.BKG_IMAGE = strValue
    
    Log("Background file to load is " & strValue)
    
    If File.Exists(File.DirAssets, strValue) Then
        bd.Initialize(LoadBitmap(File.DirAssets,strValue))
        bd.Gravity = Gravity.FILL
        Activity.Background = bd
    Else
        Log("The file does not exist!!")
    End If
    
    
End Sub

Sub btnSave_Click
    'save all settings to file
    '1) background filename
    '2) Night Mode 1,2,3 1=On 2=Off 3=Auto
    '3) Night Mode ON time
    '4) Night Mode OFF time
    '5) Thumbnail Type 1=flower 2=cosmos 3=arabic
    '6) Reserved
    
    Dim us1, us2, us3, us4, us5, us6, lineData As String
    
    If Main.THUMBNAIL_IMAGE = "flower" Then Main.THUMBNAIL_IMAGE = "1"
    If Main.THUMBNAIL_IMAGE = "cosmos" Then Main.THUMBNAIL_IMAGE = "2"
    If Main.THUMBNAIL_IMAGE = "arabic" Then Main.THUMBNAIL_IMAGE = "3"
    
    us1 = Main.BKG_IMAGE
    us2 = Main.NIGHT_MODE
    us3 = Main.NIGHT_MODE_ON
    us4 = Main.NIGHT_MODE_OFF
    us5 = Main.THUMBNAIL_IMAGE
    us6 = Main.SETTINGS_RESERVE
    
    lineData = us1 & us2 & us3 & us4 & us5 & us6
    Log("userSettings Write data is " & lineData)
    
    'make file
    Dim writeLine As TextWriter
    
    writeLine.Initialize(File.OpenOutput(File.DirInternal,"userSettings.txt",False))
    
    writeLine.WriteLine(lineData)
    
    writeLine.Close
    
    Activity.Finish
    
End Sub
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
And this is the IDE error that I'm getting...

Backup Error.JPG
 
Upvote 0
Top