Closed lasithalankajeewa closed 4 months ago
Hi @lasithalankajeewa , that sounds quite odd. Is the app actually doing anything with the barcode scanner? Or it's just a simple app that has nothing to do with the scanner, but somehow connect/disconnect of the scanner causes the app to navigate? (I didn't see any code in the app that actually uses the scanner device, but perhaps I missed it.)
Hi @lasithalankajeewa. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Hi @Eilon ,
Thank you for looking into this. I completely understand the confusion. Unfortunately, I am unable to share the full application as it is proprietary to my company. However, I have created a sample application to demonstrate the issue, and it seems to replicate the same behavior.
In this sample application, I have added a button to the index page that navigates to the counter.razor page. Whenever a barcode scanner is connected or disconnected from counter.razor page to the Android device, the app returns to the initial index.razor page. i don't know whether it is returning to index.razor or complete restart the app . This behavior is very similar to what occurs in the actual application, even without explicit code related to the scanner.
I hope this provides some clarity regarding the issue. Please let me know if there are any further details or specific information that would be helpful for solve this.
@lasithalankajeewa got it, understood. As long as the bug repros with the app you showed, that's fine. The thing is, because it's not actually using the bar code scanner, I have a hard time imagining how the two could possibly interact with each other.
Does connecting/disconnecting the bar code scanner cause some sort of command to be sent to the device that could cause navigation? Like some browser navigation event?
Could you add some code to the app to see if it is fully restarting instead of just a navigation?
Unfortunately with this bug I don't see how we could reproduce this locally without the bar code scanner so we'll likely need more information to understand where the issue is.
Hi @lasithalankajeewa. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Hi @Eilon , Thank you for your understanding. I have conducted extensive testing with various Android devices and different barcode scanners, and the issue persists across all of them. This leads me to believe that it might be related to the input method change on the Android device when the barcode scanner is connected, essentially switching from the virtual keyboard to the barcode reader. Similarly, disconnecting the scanner could trigger a switch from the barcode reader back to the virtual keyboard. This is just a thought. I might be completely wrong.
I have also included the log output pertaining to this particular occurrence in "Relevant log output" section. While I find these logs puzzling, I am hopeful that you might be able to identify some relevant insights from them.
In addition, I am keen to understand if any specific segments of the code need further scrutiny or modification. If there are particular sections or functionalities that you suggest I should focus on, please do let me know.
@lasithalankajeewa interesting. Were you able to determine if it's the app crashing, or just doing some navigation internally? I didn't see anything in the log that looked like a crash to me, but I'm not familiar with a lot of Android things.
Hi @lasithalankajeewa. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@Eilon I don't think it's crashing. It just navigated to the initial page. This is happening in android only. Windows version working fine
@lasithalankajeewa OK that's good to know. Can you test with a regular WebView as well and see what happens? Instead of BlazorWebView, use a regular WebView and point it to an arbitrary URL, like https://bing.com
, then when it loads navigate in it to some page. Then do the barcode connect/disconnect and see if it causes the regular WebView to navigate.
@Eilon where should i change this WebView and URL? can you mention the file location?
@lasithalankajeewa I'm suggesting to temporarily change your app (or just create a new app) with only a regular WebView set to a web page, use it to navigate, and then try the bar code reader. I'm trying to understand if this issue is related to a conflict between all webviews and the bar code reader.
Hi @lasithalankajeewa. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@Eilon I tried the WebView. Same happened as BlazorView. If you want to look what i implemented, I have created the WebView in the https://github.com/lasithalankajeewa/Scanner-Test-BL.git this git repository(same repo) as a separate branch,
@lasithalankajeewa interesting. Then I strongly suspect it's something that the bar code reader itself is doing, perhaps by sending fake keypresses to the OS, which if it happens to be on a WebView, causes a navigation to happen. I think sending keypresses is how some bar code readers work - they register themselves as a 'keyboard' and then when you scan bar codes they 'type in' the numbers that they detect.
Now I'm even wondering if the same thing happens in a regular web browser without .NET MAUI at all. If you open Chrome on the device, load any site, navigate (click links, etc.), and then do the bar code reader connect/disconnect, does that cause the navigation to happen? If so, then I suggest contacting the manufacturer of the bar code reader.
@Eilon I tried it on the chrome browser. But nothing happened in the Chrome browser. Also, I tried to use different barcode scanner devices as well. in there also same navigation issue happened. So, I don't think it's happened because of barcode scanner device. This is a big issue for my MAUI Hybrid app
@Eilon Any updates?
This is expected behaviour. Disconnecting/Connecting the barcode scanner is acting as a Physical keyboard as you correctly described.
Doing this will cause the app the recycle, the same as if the device language was changed.
The problem with navigation you are seeing is that the app doesn't restore the navigation state when it is stopped and restarted. You will observe the same behaviour if the app is moved to the background and stopped by the system, then switching back to the app.
@konradzuse yes you are correct. The same thing happening when the language changed. Do you have any solution to fix the issue?
As far as I know there isn't a built in solution. Maybe this is handled if you're using Shell navigation?
In my app, I have to handle OnSleep/OnResume, and save and restore the app's state manually. It's a mess of interfaces on each page, and json serialisation steps.
When the app restores, the user sees each page of the navigation stack drawing one over the next. It's not very slick, but it works.
If this is related to the scanner triggering an app recycle, is there no flags you can set KeyboardHidden
in the list of things in ConfigurationChanges
of the activity attribute:
[Activity(..., ConfigurationChanges = ... | ConfigChanges.KeyboardHidden)]
I did notice this issue in .NET7 and it seems to have gotten worse in .NET8. The issue I'm facing in .NET8 is that the app goes to a black screen when a Bluetooth keyboard is connected or disconnected from the Android device. I'm having this issue with an app that I just recently updated to .NET8 from 7. That app does not seem to have any issue with being placed in the background... This issue happens with a fresh .NET8 Blazor MAUI project. This issue does not seem to happen with a fresh .NET7 Blazor MAUI project but it does send you to the home page.
If this is related to the scanner triggering an app recycle, is there no flags you can set
KeyboardHidden
in the list of things inConfigurationChanges
of the activity attribute:[Activity(..., ConfigurationChanges = ... | ConfigChanges.KeyboardHidden)]
This comment almost helped me solve my problem. I needed both (ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden) to ignore when a keyboard was added or removed.
I am going to close this as resolved using Android's designed things. Android likes to refresh activities at will, and these are the ways to say no to it.
Description
When using a physical barcode reader on the Android version of the .NET MAUI Blazor app, the application unexpectedly returns to the initial index page when attempting to connect or disconnect the barcode reader to the android device. This behavior occurs consistently, disrupting the expected flow of the application and causing inconvenience to the user experience.
Steps to Reproduce
When Connecting the Barcode Reader
When Disconnecting the Barcode Reader
Link to public reproduction project repository
https://github.com/lasithalankajeewa/Scanner-Test-BL.git
Version with bug
7.0.86
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 13
Did you find any workaround?
No response
Relevant log output