Bug? [B4A] Intent Based Camera stops working in certain conditions 🤯

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone, I'm using this method by @Erel to take a picture from Android in my app released months ago.
Since some days, some customers told me that the "take picture" button is not working anymore, randomly.

After some investigation in my code, I could not find the problem... the only thing I noticed was that the notification that should appear from the "KeepRunningService" is not shown.

I tried starting from the original example code, excluding all my things in this way.

And i manged to replicate at least one scenario that can cause the problem, it proves that there is some sort of problem.

  1. Open the App
  2. Click on the only button to take a picture (but the notification still not shown even with the original code, I remember in the past that it was shown)
  3. System camera opens
  4. Take a picture
  5. Confirm
  6. See the result in the ImageView
You can repeat this procedure as many times you want, it will work (based on my repeated tests)



After confirming that with this flow it works correctly, proceed by doing the following in order to TRIGGER THE BUG:
  1. Put a breakpoint on line 58 Wait For ion_Event (MethodName As String, Args() As Object)
  2. Execute one more time the WORKING PROCEDURE explained above
  3. The code will be blocked on the breakpoint, simply go on (it will work)
  4. TRY AGAIN TO TAKE A PICTURE
At this point it will no longer work... and there is more, the Button_Click sub is not trigger anymore... is like the button is not liked with its event anymore...

At minute 0:13 the long pause is because I'm setting the breakpoint

What could be the problem o_O?

Thanks in advance
 

Mike1970

Well-Known Member
Licensed User
Longtime User
I found that putting a sleep between the StartActivityForResult and the Wait For ion_Event it does not freeze anymore, and the camera opens again...
(Note: I tried putting the sleep directly inside StartActivityForResult, but in this way does not work)

But I don't know what is going on, so I don't know if this is just a coincidence, I don't know if it can happen again in some other circumstances.

B4X:
StartActivityForResult(i)
Sleep(10)
Wait For ion_Event (MethodName As String, Args() As Object)
 

Mike1970

Well-Known Member
Licensed User
Longtime User
The fact that it doesn't work with the breakpoint doesn't mean that it is a real error.
No, in fact the breakpoint is the only way I found to reproduce it in a wanted manner, but this problem happens in production on clients phones.
It randomly happens, it is impossible to reproduce in other ways.

I confirm that the problem exists because it happened in first person too, just one time, while I was trying to trigger it (without breakpoints, it was in release mode):
I took 1 picture (this number is also random), then stop... impossible to take other pictures... the button still shows its animation when clicked (it was not disabled), it's like if when this happens the button (event) that started the intent lose his linking with the callback somehow. The exact same behavior that you can reproduce with the breakpoint.

So... if the same exact problem exhibit in release, and then there is even a single way to reproduce it in a controlled manner, it means that some strange behavior exists.
 
Top