Black Screen of Death

DimChrisDimChris USMember ✭✭✭

I'm trying to figure out in my customer what causes black screens of death. The apk in different places causes a black screen of death and application stucks. I have place exceptions almost every where i will send you an examample from my code:
What can cause this black screens???

I will saw you more often activity.

Here is my class:

       class MyListViewAdapterInventory : BaseAdapter<InventoryPreviewClass>
    {
        public List<InventoryPreviewClass> mitems;
        private Context mContext;
        private int mRowLayout;
        private int[] mAlternatingColors;


        public MyListViewAdapterInventory(Context context, int rowLayout, List<InventoryPreviewClass> items)
        {
            mitems = items;
            mContext = context;
            mRowLayout = rowLayout;
            mAlternatingColors = new int[] { 0xF2F2F2, 0xbfddff };

        }
        public override int Count
        {
            get
            {
                return mitems.Count;
            }
        }
        public override long GetItemId(int position)
        {
            return position;
        }
        public override InventoryPreviewClass this[int position]
        {
            get
            {
                return mitems[position];
            }

        }
        public override View GetView(int position, View convertView, ViewGroup parent)
        {



            View row = convertView;
            if (row == null)
            {
                row = LayoutInflater.From(mContext).Inflate(Resource.Layout.InventoryPreview, null, false);

            }


             row = LayoutInflater.From(mContext).Inflate(Resource.Layout.InventoryPreview, null, false);
                row.SetBackgroundColor(GetColorFromInteger(mAlternatingColors[position % mAlternatingColors.Length]));
            TextView txtInventoryID = row.FindViewById<TextView>(Resource.Id.txtInventoryID);
                txtInventoryID.Text = mitems[position].InventoryItemID;
            TextView txtInventoryName = row.FindViewById<TextView>(Resource.Id.txtInventoryName);
                txtInventoryName.Text = mitems[position].InventoryItemName;
            TextView txtInventoryPrice = row.FindViewById<TextView>(Resource.Id.txtInventoryPrice);
                txtInventoryPrice.Text = mitems[position].InventoryItemPrice.Replace(",", ".");
            Button ExtraBtn = row.FindViewById<Button>(Resource.Id.ExtrasBtn);

                ExtraBtn.Click += (sender, e) =>
                {
                    try
                    {
                        Connection.InventoryItemID = mitems[position].InventoryItemID;
                        Connection.InventoryItemName = mitems[position].InventoryItemName;
                        Connection.RetailPrice = mitems[position].InventoryItemPrice;
                        Toast toast = Toast.MakeText(mContext, txtInventoryName.Text, ToastLength.Short);
                        toast.Show();
                        mContext.StartActivity(typeof(ExtrasPreviewMain));
                    }
                    catch (Exception ex)
                    {
                        Toast toast = Toast.MakeText(mContext, Convert.ToString(ex), ToastLength.Long);
                        toast.Show();
                    }

                };




            return row;

        }
        private Color GetColorFromInteger(int color)
        {
            return Color.Rgb(Color.GetRedComponent(color), Color.GetGreenComponent(color), Color.GetBlueComponent(color));
        }

And here is my activity Main when running:

            private List<InventoryPreviewClass> mItems;
            private ListView mlistview;
            private EditText mSearch;
            private EditText etSearchAlwaysOn;
            private LinearLayout mContainer;
            private bool mAnimatedDown;
            private bool mIsAnimating;
            private MyListViewAdapterInventory mAdapter;
            string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "student.db3");
            SQLiteConnection db;
            private TextView mTxtHeaderFirstName;
            private TextView mTxtHeaderLastName;

            private bool mFirstNameAscending;
            private bool mLastNameAscending;
            protected override void OnCreate(Bundle savedInstanceState)
            {
                try
                {
                    ActionBar.SetHomeButtonEnabled(true);
                    ActionBar.SetDisplayHomeAsUpEnabled(true);

                    base.OnCreate(savedInstanceState);

                    SetContentView(Resource.Layout.InventoryPreviewMain);
                    OverridePendingTransition(Resource.Layout.trans_left_in, Resource.Layout.trans_left_out);

                    mSearch = FindViewById<EditText>(Resource.Id.etSearch);
                    etSearchAlwaysOn = FindViewById<EditText>(Resource.Id.etSearchAlwaysOn);
                    mContainer = FindViewById<LinearLayout>(Resource.Id.llContainer);

                    mTxtHeaderFirstName = FindViewById<TextView>(Resource.Id.txtHeaderFirstName);
                    mTxtHeaderLastName = FindViewById<TextView>(Resource.Id.txtHeaderLastName);


                    mTxtHeaderFirstName.Click += mTxtHeaderFirstName_Click;
                    mTxtHeaderLastName.Click += mTxtHeaderLastName_Click;

                    mSearch.Alpha = 0;
                    mContainer.BringToFront();

                    mSearch.TextChanged += mSearch_TextChanged;
                    etSearchAlwaysOn.TextChanged += EtSearchAlwaysOn_TextChanged;

                    mlistview = FindViewById<ListView>(Resource.Id.InventoryList);
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, Convert.ToString(ex), ToastLength.Short).Show();
                }

                try
                {
                    db = new SQLiteConnection(dpPath);
                    var table = db.Query<InventoryPreviewClass>("select * from InventoryPreviewClass where CategoryID =" + Connection.CategoryID+ "");
                    mItems = new List<InventoryPreviewClass>();
                    foreach (var item in table)
                    {

                        mItems.Add(new InventoryPreviewClass() { InventoryItemID = item.InventoryItemID, InventoryItemName = item.InventoryItemName, InventoryItemPrice = item.InventoryItemPrice });


                    }
                    MyListViewAdapterInventory adapter = new MyListViewAdapterInventory(this, Resource.Layout.InventoryPreview, mItems);
                    mlistview.Adapter = adapter;
                    mlistview.ItemClick += Mlistview_ItemClick;
                }
                catch
                {

                }
                try
                {
                    if (SearchAlwaysOn == true)
                    {
                        var param = (LinearLayout.LayoutParams)etSearchAlwaysOn.LayoutParameters;
                        var WidthParam = ViewGroup.LayoutParams.MatchParent;
                        var HeigthParam = ViewGroup.LayoutParams.WrapContent;
                        param.Width = WidthParam;
                        param.Height = HeigthParam;
                        mIsAnimating = true;
                    }
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, Convert.ToString(ex), ToastLength.Short).Show();
                }


            }

Posts

  • robbitrobbit CNMember ✭✭

    try this:

    private void initData()
            {
                db = new SQLiteAsyncConnection(dpPath);
                db.CreateTableAsync<InventoryPreviewClass>().ContinueWith(t => {
                    Console.WriteLine("Table created!");
                });
                var query= db.Table<InventoryPreviewClass>().Where(v=>v.InventoryItemID.Equals("1"));
                query.ToListAsync().ContinueWith(t => {
                    mItems = new List<InventoryPreviewClass>();
                    foreach (var item in t.Result)
                        mItems.Add(new InventoryPreviewClass() { InventoryItemID = item.InventoryItemID, InventoryItemName = item.InventoryItemName, InventoryItemPrice = item.InventoryItemPrice });
    
                });
                MyListViewAdapterInventory adapter = new MyListViewAdapterInventory(this, Resource.Layout.InventoryPreview, mItems);
                mlistview.Adapter = adapter;
                mlistview.ItemClick += Mlistview_ItemClick;
            }
    
  • DimChrisDimChris USMember ✭✭✭

    Thank you for your answer!! It solved my problem!

Sign In or Register to comment.