我试图在我的客户的手机中找出导致死亡黑屏的原因。 apk在不同的地方和随机的时刻导致黑屏死机和应用程序卡住。我几乎到处都有例外,但我没有收到任何异常消息。我会从我的代码中发送一个examample: 什么能导致这种黑屏?
这是我的班级:
public class AppCompatCookieActivity extends AppCompatActivity {
@Override
public void onResume() {
super.onResume();
// start cookie syncing for pre-lollipop devices
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.getInstance().startSync();
}
}
@Override
public void onPause() {
// stop cookie syncing for pre-lollipop devices
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.getInstance().sync();
}
super.onPause();
}
public final void enableCookies(WebView webView) {
// enable javascript (has security implications!)
webView.getSettings().setJavaScriptEnabled(true);
// enable cookies.
CookieManager.getInstance().setAcceptCookie(true);
// enable fileScheme cookies (has security implications!)
// it is recommended to comment this out should you find it not necessary
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
CookieManager.getInstance().setAcceptFileSchemeCookies(true);
}
// enable third party cookies
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}
}
}
这是我在运行时的主要活动:
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));
}
}