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:


Sample code of the “click item”

 async void OnListItemClicked(object o, ItemTappedEventArgs e)
            ((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)

        //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;
                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 =;

        if(Device.RuntimePlatform != Device.iOS)
            Children.Add(new ChatPage(conversation, user));
            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 *