In .Net MAUI Bluetooth Connection disconnect navigation between the Pages

Jeyamani Sekar 20 Reputation points
2025-10-16T05:22:23.6566667+00:00

In this I will explain the detailed issue and flow, Once the application was open on first launch it will be Language Selection (Content Page) Page, it will have 6 (buttons) it will a language name of it, while clicking any language based on that all other screens will be displayed, the next screen will User Mode(Content Page) selection it will have 2 (buttons) it will be registered and unregistered, 

 if the user clicks registered mode, it will navigate to Login Page(Content Page) will allow user to enter the username and password (Entry) and Login (Button), it will login the user and navigate to selection (Content Page), it will have 6 content page ,  it will change based on the user selection on the content view, it will have 6 SelectionContentview (content view) for that user can connect Bluetooth and wifi, and they will navigate to Menu Page (Content Page) it will have menu items which has 4 menu items (in the below we have 9 content view in that first 4 only will show in this) while clicking these the content view will based on Menu Page and also one hamburger menu while clicking on it  will show the 9 menu using content view. Those Content View will act as pages ony those only will show with that few things in menupage like logout sync and refresh and few other details. Now I will explain the 9 content views. 

  1. Dashboard view (Content view 1): 

It will have radslider which has the item source as List<ContentView> and few other details. It will have 3 Content views. 

Main Dashboard (Dashboard Content View1): It will load the value that we get form the Bluetooth or wifi device  

Second Dashboard (Dashboard Content View2): It will load the value that we get form the Bluetooth or wifi device 

Third Dashboard (Dashboard Content View3): It will load the value that we get form the Bluetooth or wifi device as the graph which will load values which was selected by the user in above dropdown 

 

These device values will be getting every second from the device and will update these three content views. Even we change the content view to any other screen it needs to get but right now it was not like that. 

Settings View (Content View2): 

It will have radslider which has the item source as List<ContentView> and few other details. It will have 4 Content views. 

 

Mian Settings (Settings Content view 1):  It will few details regarding the reports need to generate, and process need to follow. 

Second Settings (Settings Content View 2): It will show the theme, version, help, and support of the app.  

Third Settings (Settings Content View3): it will have setup of navigation that need to follow while selecting the selection wheel based on the mode 

Fourth Settings (Settings Content view 4): it will show abot the terms and conditions and company policy 

 

Client View (Content View 3): 

It will have radslider which has the item source as List<ContentView> and few other details. It will have 4 Content views. 

 

 

Main Client (Client Content view 1): It will show the client’s details such as name, phone number, etc. 

Second Client (Client Content view 2): It will show the client’s additional details 

Third Client (Client Content View 3): It will show the additional details which we need to show in the reports. 

Fourth Client (Client Content view 4): It will show the list of the customer that is linked with the logged user. 

 

Reports View (Content View 4): 

It will have radslider which has the item source as List<ContentView> and few other details. It will have 4 Content views. 

Main Report (Report Content View 1): It will show the report setting that what are needed to show in report 

Second Report (Report Content View 2): It will show the addition of report settings that need to be shown in the report. 

Third Report (Report Content View 3): It will show the addition of report settings that need to be shown in the report. 

Fourth Report (Report Content View 4): It will show the list of reports that was created by the user based on the customer selected in the screen user can share and can open the pdf and edit it. 

Profile View (Content View 5): 

It will show the user details such as name, phone number, etc., for the user to logged in. 

Device View (Content view 6): 

 It will show the device details such as device name, serial number,etc. 

Test Selection View (Content View 7): 

  It will navigate the user to selection page (Content Page) 

Test Connection View (Content View 8): 

  It will have the button to test the Bluetooth or Wi-Fi connection that was connected. With serial number of the device 

Database View (Content View 9) : 

It will have 2 buttons to export and import the sqlite database for the application if needed. 

If the User Clicks Unregistered, it will automatically navigates to selection (Content Page) SelectionContentview (content view) for that user can connect Bluetooth and wifi rest are same as registered mode that I mentioned above. 

Everythings works fine except while navigating between the menu items (dashboard,clients,settings,Reports) it took longer time to navigate due to that the Bluetooth connection getting disconnected while navigating between these, we can’t be able to find out how to reduce the time for navigation and also control the disconnect.   

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tony Dinh (WICLOUD CORPORATION) 3,585 Reputation points Microsoft External Staff
    2025-10-16T07:24:31.2333333+00:00

    Hello @Jeyamani Sekar !

    In well-designed application, device communication (like Bluetooth or WiFi) should be managed independently of the UI layer, which mean the connection and data polling should persist regardless of navigation or page lifecycle events (e.g., OnAppearing or OnDisappearing). Tying the Bluetooth connection to a ContentPage's state can cause issues like disconnections during navigation, as you're experiencing, because page loading can block the UI thread or interrupt event handlers.


    Navigation Performance Optimizations

    Regarding to the navigation, the lag is likely due to re‑creating and re‑binding complex views (especially RadSliders with multiple ContentViews) every time you switch. Here's what I can give to reduce it:

    • Cache ContentViews instead of re‑instantiating
      • Keep a dictionary of already created views in your MenuPageViewModel.
      • Swap them into a ContentPresenter instead of navigating to new pages.
      • This avoids full page lifecycle overhead.
    • Lazy load subviews
      • For RadSlider with multiple subviews, don’t try create all at once but create only the visible one, and load others on demand.
    • Preload critical views in background
      • After login, spin up lightweight instances of Dashboard, Settings, Client, Reports in a background task. That way, when the user navigates, they’re already in memory.
    • Simplify XAML
      • Replace deep nested StackLayouts with Grid or AbsoluteLayout.
      • Use compiled bindings (x:DataType) to reduce runtime binding cost.
      • For lists, use CollectionView with RecycleElement.
    • Avoid NavigationPage overhead
      • Instead of pushing/popping pages, keep a single MenuPage with a ContentPresenter and swap views inside it. This is much faster than full page navigation (which involves animations and lifecycle overhead).

    Bluetooth/Wi‑Fi Connection Persistence

    Right now, your device polling is tied to the UI lifecycle. You need to decouple device communication from the UI:

    • Move device communication into a background service
      • Create a singleton DeviceService that manages Bluetooth/Wi‑Fi connections and run polling on a background thread (Timer or Task.Run with CancellationToken):
            public class DeviceService {
                private Timer _pollTimer;
                public event EventHandler<DeviceDataEventArgs> DataUpdated;
         
                public void StartPolling() {
                    _pollTimer = new Timer(async _ => await PollDeviceData(), null, 0, 1000);
                }
         
                private async Task PollDeviceData() {
                    var data = await ReadFromDevice();
                    DataUpdated?.Invoke(this, new DeviceDataEventArgs(data));
                }
            }
        
    • UI subscribes/unsubscribes
      • Each ContentView (Dashboard, etc.) subscribes to DataUpdated in OnAppearing and unsubscribes in OnDisappearing.
      • Use Device.BeginInvokeOnMainThread to update UI safely.
    • Enable background modes
      • On Android: use a ForegroundService for Bluetooth.
      • On iOS: enable bluetooth-central background mode in Info.plist.
    • Graceful reconnection
      • Add retry logic with exponential backoff if the connection drops.
      • Notify the user only if reconnection fails after several attempts.

    Once you isolate it into a background service and optimize navigation to reuse views, both problems (lag + disconnects) will disappear.


    I hope this helps! Let me know if you have questions!


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.