1

Je développe actuellement une application Xamarin (PCL) multi plate-forme que je suis en train de tester sur mes appareils physiques et émulateurs Android. L'application fonctionne parfaitement sur les téléphones haut de gamme, mais "se bloque de façon inattendue" sur le Samsung S4 et de tels téléphones bas de gamme. Il se bloque seulement après avoir effectué plusieurs activités et tâches. Je suppose que cela a quelque chose à voir avec la capacité de tâche-thread de ces téléphones. Si j'ai raison à cet égard, comment suis-je censé rendre mon application telle qu'elle fonctionne sans problème et sans erreur sur tous les téléphones? Éditer - L'erreur indique «L'application s'est fermée de façon inattendue». Cette erreur n'apparaît pas sur une ligne spécifique car elle n'a rien à voir avec le code. Il casse seulement sur certains téléphones «plus anciens» lorsque de nombreuses activités sont effectuées. Exemples d'activités: ajouter des données à la base de données, les mettre à jour/les supprimer, passer d'une activité à une autre, afficher des calendriers et des camemberts à partir de données entrées par l'utilisateur.Xamarin Forms - Thread Efficiency

Edit 2 -Certains du Code qui traite des images:

Xaml:

<ScrollView HorizontalOptions="Fill" Orientation="Horizontal"> 
           <StackLayout Orientation="Vertical" BackgroundColor="GhostWhite" > 
            <StackLayout Orientation="Horizontal" BackgroundColor="GhostWhite" > 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="dairy" Image="{Binding Dairy_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="alcohol" Image="{Binding Alcohol_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="eggs" Image="{Binding Egg_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="fastfood" Image="{Binding Fastfood_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="fish" Image="{Binding Fish_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="fruit" Image="{Binding Fruit_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="grain" Image="{Binding Grain_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="legume" Image="{Binding Legume_Image}"/> 
            </StackLayout> 
            <StackLayout Orientation="Horizontal" BackgroundColor="GhostWhite" > 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="meat" Image="{Binding Meat_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="munchies" Image="{Binding Munchies_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="nuts" Image="{Binding Nut_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="potato" Image="{Binding Potato_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="soda" Image="{Binding Soda_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="sweets" Image="{Binding Sweet_Image}"/> 
             <Button HeightRequest="50" BackgroundColor="GhostWhite" WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="vegetables" Image="{Binding Vegetable_Image}"/> 
            </StackLayout> 
           </StackLayout> 

.cs:

public UserMealINC_vm(User_Profiles up, DateTime day) 
     { 
      try 
      { 
       Day = day; 
       User_pro = up; 
       Bool_Food_Type = false; 
       Food_Name = ""; 
       Type = ""; 
       Food_Weight = "0"; 
       Selected_Food = new List<string>(); 

       //All meal item are first initialized with the non-coloured images 
       Dairy_Image = "drawable/dairy.png"; 
       Alcohol_Image = "drawable/alcohol.png"; 
       Egg_Image = "drawable/eggs.png"; 
       Fastfood_Image = "drawable/fastfood.png"; 
       Fish_Image = "drawable/fish.png"; 
       Fruit_Image = "drawable/fruit.png"; 
       Grain_Image = "drawable/grain.png"; 
       Legume_Image = "drawable/legume.png"; 
       Meat_Image = "drawable/meat.png"; 
       Munchies_Image = "drawable/munchies.png"; 
       Nut_Image = "drawable/nuts.png"; 
       Potato_Image = "drawable/potato.png"; 
       Soda_Image = "drawable/soda.png"; 
       Sweet_Image = "drawable/sweets.png"; 
       Vegetable_Image = "drawable/vegetables.png"; 

       this.Button_Clicked_Food = new Command<string>((key) => 
       { 
        //Change the item selected from color to non-color, or vice-versa 

        if (Selected_Food.Contains(key)) 
        { 
         if (key == "dairy") 
         { 
          Dairy_Image = "drawable/dairy.png"; 
         } 
         else if (key == "alcohol") 
         { 
          Alcohol_Image = "drawable/alcohol.png"; 
         } 
         else if (key == "eggs") 
         { 
          Egg_Image = "drawable/eggs.png"; 
         } 
         else if (key == "fastfood") 
         { 
          Fastfood_Image = "drawable/fastfood.png"; 
         } 
         else if (key == "fish") 
         { 
          Fish_Image = "drawable/fish.png"; 
         } 
         else if (key == "fruit") 
         { 
          Fruit_Image = "drawable/fruit.png"; 
         } 
         else if (key == "grain") 
         { 
          Grain_Image = "drawable/grain.png"; 
         } 
         else if (key == "legume") 
         { 
          Legume_Image = "drawable/legume.png"; 
         } 
         else if (key == "meat") 
         { 
          Meat_Image = "drawable/meat.png"; 
         } 
         else if (key == "munchies") 
         { 
          Munchies_Image = "drawable/munchies.png"; 
         } 
         else if (key == "nuts") 
         { 
          Nut_Image = "drawable/nuts.png"; 
         } 
         else if (key == "potato") 
         { 
          Potato_Image = "drawable/potato.png"; 
         } 
         else if (key == "soda") 
         { 
          Soda_Image = "drawable/soda.png"; 
         } 
         else if (key == "sweets") 
         { 
          Sweet_Image = "drawable/sweets.png"; 
         } 
         else if (key == "vegetables") 
         { 
          Vegetable_Image = "drawable/vegetables.png"; 
         } 
         else 
         { 
          //Key out of bounds??? 
         } 

         Selected_Food.Remove(key); 
        } 
        else 
        { 
         if (key == "dairy") 
         { 
          Dairy_Image = "drawable/dairy_color.png"; 
         } 
         else if (key == "alcohol") 
         { 
          Alcohol_Image = "drawable/alcohol_color.png"; 
         } 
         else if (key == "eggs") 
         { 
          Egg_Image = "drawable/eggs_color.png"; 
         } 
         else if (key == "fastfood") 
         { 
          Fastfood_Image = "drawable/fastfood_color.png"; 
         } 
         else if (key == "fish") 
         { 
          Fish_Image = "drawable/fish_color.png"; 
         } 
         else if (key == "fruit") 
         { 
          Fruit_Image = "drawable/fruit_color.png"; 
         } 
         else if (key == "grain") 
         { 
          Grain_Image = "drawable/grain_color.png"; 
         } 
         else if (key == "legume") 
         { 
          Legume_Image = "drawable/legume_color.png"; 
         } 
         else if (key == "meat") 
         { 
          Meat_Image = "drawable/meat_color.png"; 
         } 
         else if (key == "munchies") 
         { 
          Munchies_Image = "drawable/munchies_color.png"; 
         } 
         else if (key == "nuts") 
         { 
          Nut_Image = "drawable/nuts_color.png"; 
         } 
         else if (key == "potato") 
         { 
          Potato_Image = "drawable/potato_color.png"; 
         } 
         else if (key == "soda") 
         { 
          Soda_Image = "drawable/soda_color.png"; 
         } 
         else if (key == "sweets") 
         { 
          Sweet_Image = "drawable/sweets_color.png"; 
         } 
         else if (key == "vegetables") 
         { 
          Vegetable_Image = "drawable/vegetables_color.png"; 
         } 
         else 
         { 
          //Key out of bounds??? 
         } 
         Selected_Food.Add(key); 
        } 
       });     
      } 
      catch (Exception ex) 
      { 
       App.Current.MainPage.DisplayAlert("UserMealINC_vm 1!", ex.Message, "OK"); 
      } 
     } 
+0

Cela dépend du type de blocage que vous rencontrez. Envie d'élaborer un peu plus? – Cheesebaron

+0

Quelle est l'erreur? À quoi ressemble le code? Sur quelle ligne s'écrase-t-il? – hvaughan3

+0

@ hvaughan3 J'ai édité ma question. – TigerLionCheetah

Répondre

0

Il se trouve que la mémoire de l'appareil a été débordé par se toutes les images multiples que j'avais dans mon application. (Comme suggéré par @ hvaughan3)

This link has the answer to it.

Vous essentiellement suffit d'ajouter ces deux lignes vous Android Manifest (sous Application) -

android: hardwareAccelerated = "false"
android : largeHeap = "true"