[mono-android] App Hanging
Jonathan Pryor
jonp at xamarin.com
Fri Jan 20 21:55:22 UTC 2012
Which Mono for Android version is this? The 4.0.3 beta has a number of GC and JIT fixes which may fix what you're seeing.
Also, as Tomasz Cielecki mentioned, you appear to be creating lots of Java-side objects. The emulator only allows a limited number of Java-side objects to be created (due to a 2000 global reference limit), so you want to minimize the number of Java-side objects you create (within reason).
To that end, you may want to subclass BaseAdapter and override BaseAdapter.GetView() to reuse View instances instead of creating them all at once:
https://github.com/xamarin/monodroid-samples/blob/master/ApiDemo/Tutorials/GridViewTutorial.cs#L52
- Jon
On Jan 17, 2012, at 2:17 PM, Fencer04 wrote:
> I am calling a webservice and getting 729 results in an array. I'm then out
> putting these results in to a 2 column table dynamically. Each time I run it
> chokes somewhere between the 548th and 569th row when setting the text of
> either the 1st or second column like this:
>
> resultView1.Text = outcome.PercentageRatio;
>
> It will also show a window asking if I want to wait while the debugger is
> hung on the expression "Method: Java.Lang.Object.ToString
>
> Nothing is null and the services is returning the data that I expect. Can
> someone help me out. My code is below.
>
> int rowCount = 0;
> TextView resultView1 = null;
> TextView resultView2 = null;
> foreach(GeneticOutcomes outcome in results){
> TableRow row = new TableRow(this);
> row.SetPadding(0, 10, 0, 0);
> resultView1 = new TextView(this);
> resultView1.SetTextColor(Color.White.ToArgb());
> resultView1.SetTextSize(Android.Util.ComplexUnitType.Sp, 16);
> //resultView1.LayoutParameters = new
> TableRow.LayoutParams(TableRow.LayoutParams.WrapContent, 20);
> resultView1.SetPadding(0, 0, 5, 0);
> resultView1.Text = outcome.PercentageRatio;
> row.AddView(resultView1);
> resultView2 = new TextView(this);
> resultView2.SetTextColor(Color.White.ToArgb());
> resultView2.SetTextSize(Android.Util.ComplexUnitType.Sp, 16);
> float scale = Resources.DisplayMetrics.Density;
> int pixels = (int)((325 - resultView1.Width) * scale + 0.5f);
> //resultView2.LayoutParameters = new TableRow.LayoutParams(pixels, 20);
> resultView2.SetPadding(3,0,40,0);
> resultView2.Text = outcome.GeneticString;
> row.AddView(resultView2);
> resultTable.AddView(row);
> rowCount = rowCount + 1;
> }
> ll.AddView(resultTable);
>
> --
> View this message in context: http://mono-for-android.1047100.n5.nabble.com/App-Hanging-tp5152606p5152606.html
> Sent from the Mono for Android mailing list archive at Nabble.com.
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
More information about the Monodroid
mailing list