Android Question Debug mode displays correct result but release mode doesn't

sconlon

Active Member
Licensed User
Longtime User
I am developing an app to keep track of wines in my wine fridge and have noticed an anomaly when running it in Release mode as opposed to Debug mode. I have a graphical representation of my fridge which has 12 shelves and 8 bottle positions per shelf - 4 bottles with their bottoms showing and 4 with their tops showing. I am adding the views within a For loop as below and want to have the images of tops of the bottles smaller than the bottoms.

B4X:
    curtop = 0
    Dim front As Boolean = True
    Dim mult, offset As Double
    viewno = numshelves
    For i = 1 To numshelves
        curleft = 10dip
        For j = 1 To numpositions
            Dim bottle As Button
            bottle.Initialize("bottle")
            bottle.Background = empty
            bottle.Tag = i & ":0:" & j & ":" & viewno & ":empty"
            If front Then   
                mult = 1 : offset = 0
                front = False
            Else
                mult = .6 : offset = bottlewidth*.2
                front = True
            End If
            pnlFridge.AddView(bottle, curleft, curtop + offset, bottlewidth*mult, bottlewidth*mult)
            curleft = curleft + bottlewidth + bottlegap
            viewno = viewno + 1
        Next
        curleft = 10dip
        curtop = curtop + shelfheight + shelfgap
    Next

When I run this in debug I get the image in s1.jpg which is correct but when I run in release mode I get a different result as in s2.jpg. Any ideas why this is happening?
 

Attachments

  • s1.jpg
    s1.jpg
    167.4 KB · Views: 215
  • s2.jpg
    s2.jpg
    147.6 KB · Views: 213

Star-Dust

Expert
Licensed User
Longtime User
I am developing an app to keep track of wines in my wine fridge and have noticed an anomaly when running it in Release mode as opposed to Debug mode. I have a graphical representation of my fridge which has 12 shelves and 8 bottle positions per shelf - 4 bottles with their bottoms showing and 4 with their tops showing. I am adding the views within a For loop as below and want to have the images of tops of the bottles smaller than the bottoms.

B4X:
    curtop = 0
    Dim front As Boolean = True
    Dim mult, offset As Double
    viewno = numshelves
    For i = 1 To numshelves
        curleft = 10dip
        For j = 1 To numpositions
            Dim bottle As Button
            bottle.Initialize("bottle")
            bottle.Background = empty
            bottle.Tag = i & ":0:" & j & ":" & viewno & ":empty"
            If front Then
                mult = 1 : offset = 0
                front = False
            Else
                mult = .6 : offset = bottlewidth*.2
                front = True
            End If
            pnlFridge.AddView(bottle, curleft, curtop + offset, bottlewidth*mult, bottlewidth*mult)
            curleft = curleft + bottlewidth + bottlegap
            viewno = viewno + 1
        Next
        curleft = 10dip
        curtop = curtop + shelfheight + shelfgap
    Next

When I run this in debug I get the image in s1.jpg which is correct but when I run in release mode I get a different result as in s2.jpg. Any ideas why this is happening?
can I get a bottle of wine? :p


Try change this:
B4X:
bottle.Background = image
With this:
B4X:
bottle.SetBackgroundImage(image)
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I would create the fridge using the Designer. Since you put the views that represent the bottles on a panel, then in your code you can use two cycles and the method pnlFridge.GetAllViewRecursive to fill a two dimensional array with those views.

You could also create a custom type to store data of a single bottle, like a constant: PLACE_EMPTY, PLACE_TOP, PLACE_BOTTOM, x and y (although it would be better to separate logical data and GUI data), and other (year, for example). If you store a custom type with x and y, you don't need a two dimensional array, you can use a mono dimensional or, better, a list or a map.

I would also write a routine to change at least the state of a "place for a bottle", to set if to one of the constants I wrote above; in this routine I would change the image (without bottle, bottle on front or bottom).

You could also use a StateListDrawable to represent "a bottle", a state for front, one for bottom, one for "empty" (empty place, not an empty bottle :D).
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately, you don't give enough infromation.
In which routine is the code snippet from your first post?
Where and how is the empty background defined and where are the other backgrounds defined and set?
Where and how do you set a bottle?
In your code above all positions are empty, but in the images not !?
There are two problems:
upload_2018-5-11_7-17-45.png
upload_2018-5-11_7-17-59.png

The first, when you set all empty positions in the wine fridge and the second, when you fill it with bootles.
I suspect the following: you probably set the backgrounds with the same variables without initializing a new instance for each view.
You should post a small project showing the problem so we can see what exactly you have done and how to give to a concrete advice.
I would not use buttons, I would do all this with a canvas and a Touch event.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I would not use buttons, I would do all this with a canvas and a Touch event.
I would not ImageView and a Touch event :)
 
Upvote 0

sconlon

Active Member
Licensed User
Longtime User
Thanks for all the answers guys. I'm sure there is enough info within to help resolve the problem or try a different and better approach.
 
Upvote 0
Top