My home page is a CarouselView having 5 tabs.
<CarouselView
x:Name="carouselView"
CurrentItemChanged="OnCurrentItemChanged"
Loop="False">
<CarouselView.ItemsSource>
<x:Array Type="{x:Type ContentView}">
<control:HomeTabPage/>
<control:KeyPadPage/>
<control:CallHistoryPage/>
<control:ContactsPage/>
<control:RequestTab/>
</x:Array>
</CarouselView.ItemsSource>
<CarouselView.ItemTemplate>
<DataTemplate>
<ContentView Content="{Binding}"/>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
I am loading the data on each tabs using the WeakReferenceMessenger. When swipe the tabs or click I send a message using WeakReferenceMessenger like below:
void OnCurrentItemChanged(object sender, CurrentItemChangedEventArgs e)
{
int index = carouselView.Position;
AddWeakReferenceMessenger(index);
}
private void AddWeakReferenceMessenger(int index)
{
if (index == 0)
{
WeakReferenceMessenger.Default.Send(new HomeTabChangeMessage("home_tab"));
}
else if (index == 1)
{
WeakReferenceMessenger.Default.Send(new HomeTabChangeMessage("keypad_tab"));
}
else if (index == 2)
{
WeakReferenceMessenger.Default.Send(new HomeTabChangeMessage("history_tab"));
}
else if (index == 3)
{
WeakReferenceMessenger.Default.Send(new HomeTabChangeMessage("contacts_tab"));
}
else if (index == 4)
{
WeakReferenceMessenger.Default.Send(new HomeTabChangeMessage("requests_tab"));
}
}
And I am subscribing it on child tabs like below and start loading data via API call:
WeakReferenceMessenger.Default.Register<HomeTabChangeMessage>(this, (r, m) =>
{
if (m.Value == "keypad_tab")
{
Debug.WriteLine("isKeyPadLoaded:>>" + Utility.isKeyPadLoaded);
if (!Utility.isKeyPadLoaded)
{
Utility.isKeyPadLoaded = true;
//Start the API call from here
}
}
});
Here I am using Boolean variables to check the tabs are already loaded or not. Its default value is false and after loading a tab I am setting its value as true. So If I view the same tab again it will start the API calls. The same way I subscribed the WeakReferenceMessenger on all the other child tabs. The feature was working fine with this approach.
My Problem:
If I load all the tabs, then log out from the app and log in again the tabs are not loading.
I have created a screen recorder video and upload it here for the easy understanding.
When I logging out and logging in I am resetting the value of all the Boolean variable to false. But When I view the tabs the data is not loading.
I printed the value of Boolean variable when I logging out and logging in and it is showing false initially and true after that. That means the WeakReferenceMessenger invoking multiple times.

I suspect the issue is due to the WeakReferenceMessenger's multiple invoking; because of that the code execution is not going inside of the if block of the bool value check.
Do I need to unregister the WeakReferenceMessenger or something?
I created a demo project based on this issue, but the issue was not replicating on this demo project. For reference, I upload Here