android – Xamarin.forms – Background color changes when activity is about to load-ThrowExceptions

Exception or error:

I have a activity with a listView that got items which drive us to another activity called Main Chat. The problem resides when I touch one of those items. Before it loads the respective activity, the background color of the main activity changes to green. I’ve inspected my code but I can’t find any sample of code that does that type of behavior. Here’s the video of what happen and the following code:

Video: https://files.fm/u/7nt2szdy#/view/20200213_115056.mp4;play

Sample code of the “click item”

 async void OnListItemClicked(object o, ItemTappedEventArgs e)
    {
        try
        {
            ((ListView)o).SelectedItem = null;

            var vListItem = e.Item as Classes.ClassConversation.ResultadoConversation;
            var getResposta = await Servicos.Servicos.Token(vListItem.institutionId);

            if (getResposta)
                await Navigation.PushAsync(new Chat.MainChat(vListItem, user2, true));
        }
        catch (Exception)
        {
            await DisplayAlert(Languages.AppResources.Notifications, Languages.AppResources.ErrorOccurred, "Ok");
        }
    }

Sample code of the Main Chat”

  public MainChat (Classes.ClassConversation.ResultadoConversation conversation, Classes.ClassUser.Result user, bool Resposta)
    {
        InitializeComponent();

        //Muda a cor do texto e o local da tab no android
        UnselectedTabColor = Color.FromHex("#80FFFFFF");
        SelectedTabColor = Color.White;

        //Muda a cor do toolbar e texto 
        if (Resposta == true)
        {
            ((NavigationPage)Xamarin.Forms.Application.Current.MainPage).BackgroundColor = (Color)App.Current.Resources["colorPrimary"];
            ((NavigationPage)Xamarin.Forms.Application.Current.MainPage).BarBackgroundColor = (Color)App.Current.Resources["colorPrimary"];
            ((NavigationPage)Xamarin.Forms.Application.Current.MainPage).BarTextColor = (Color)App.Current.Resources["white"];
        }

        if (conversation.OtherUser == null)
        {
            conversation.OtherUser = new Classes.ClassConversation.User();
            if(conversation.user_From.rowKey == user.rowKey)
            {
                conversation.OtherUser = conversation.user_To;
            }
            else
            {
                conversation.OtherUser = conversation.user_From;
            }
        }

        //Set Name and image of the other user and chat title
        if (conversation.OtherUser.photoUri != null)
            ImageUser.Source = new UriImageSource { CachingEnabled = true, Uri = conversation.OtherUser.photoUri, CacheValidity = new TimeSpan(800000, 0, 0, 0) };

        TitleChat.Text = conversation.title;
        NameOtherUser.Text = conversation.OtherUser.name;

        if(Device.RuntimePlatform != Device.iOS)
            Children.Add(new ChatPage(conversation, user));
        else
            Children.Add(new ChatPageIos(conversation, user));

        Children.Add(new Report(conversation, user));

        result = conversation;
    }
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *