当我最小化并返回到应用程序时,应用程序崩溃,屏幕变黑

时间:2012-09-27 19:23:15

标签: android crash minimize

当我最小化时,我的应用程序崩溃,关闭3G并返回应用程序。 此应用程序从互联网(SAX Parser)捕获XML信息,然后按主页按钮,关闭3G并返回应用程序看起来为黑色。

感谢您的帮助

我的主要代码

    SitesList5101 sitesList5101 = null;


static final int DIALOG_ERROR_CONNECTION = 1;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.xmlultimoterceroo);

    TextView nemotecnico[];
    TextView precio[];
    TextView variacion[];
    TextView ttransado[];
    TextView pcierre[];
    TextView utrans[];

    TableRow tr[] = new TableRow[108];
    TableLayout layout = (TableLayout)findViewById(R.id.layout);


            try{

                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();

                URL sourceUrl = new URL("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=5101");
                MyXMLHandler5101 myXMLHandler = new MyXMLHandler5101();
                xr.setContentHandler(myXMLHandler);
                xr.parse(new InputSource(sourceUrl.openStream()));

            } catch (Exception e){
                System.out.println("XML PArsing Exc =" +e);
            }




    sitesList5101 = MyXMLHandler5101.sitesList5101;

    nemotecnico = new TextView[sitesList5101.getNemotecnico().size()];
    precio = new TextView[sitesList5101.getPrecio().size()];
    variacion = new TextView[sitesList5101.getVariacion().size()];
    ttransado = new TextView[sitesList5101.getTtransado().size()];
    pcierre = new TextView[sitesList5101.getPcierre().size()];
    utrans = new TextView[sitesList5101.getUtrans().size()];

    for(int i = 0; i < sitesList5101.getRegistro().size(); i++){

        nemotecnico[i] = new TextView(this);
        nemotecnico[i].setText(" "+ sitesList5101.getNemotecnico().get(i));
        nemotecnico[i].setTextColor(Color.parseColor("#000000"));
        nemotecnico[i].setTypeface(null, Typeface.BOLD);


        precio[i] = new TextView(this);
        precio[i].setText(" "+ sitesList5101.getPrecio().get(i));
        precio[i].setTextColor(Color.parseColor("#333333"));
        precio[i].setTypeface(null, Typeface.BOLD);


        variacion[i] = new TextView(this);
        variacion[i].setText(" "+ sitesList5101.getVariacion().get(i));
        variacion[i].setTextColor(Color.parseColor("#000000"));
        variacion[i].setTypeface(null, Typeface.BOLD);


        ttransado[i] = new TextView(this);
        ttransado[i].setText(" "+ sitesList5101.getTtransado().get(i));
        ttransado[i].setTextColor(Color.parseColor("#333333"));
        ttransado[i].setTypeface(null, Typeface.BOLD);


        pcierre[i] = new TextView(this);
        pcierre[i].setText(" "+ sitesList5101.getPcierre().get(i));
        pcierre[i].setTextColor(Color.parseColor("#333333"));
        pcierre[i].setTypeface(null, Typeface.BOLD);

        utrans[i] = new TextView(this);
        utrans[i].setText(" "+ sitesList5101.getUtrans().get(i));
        utrans[i].setTextColor(Color.parseColor("#333333"));
        utrans[i].setTypeface(null, Typeface.BOLD);

        nemotecnico[i].setTextSize(10);
        precio[i].setTextSize(11);
        variacion[i].setTextSize(11);
        ttransado[i].setTextSize(11);
        pcierre[i].setTextSize(11);
        utrans[i].setTextSize(11);

        Pattern pattern = Pattern.compile("^([a-z: ]*)?+(\\+?[0-9]+([,\\.][0-9]*)?)$");
        Matcher matcher = pattern.matcher(sitesList5101.getVariacion().get(i));
        if(!matcher.matches())

        variacion[i].setTextColor(Color.parseColor("#ff0000"));
        else
        variacion[i].setTextColor(Color.parseColor("#006633"));

    }

    int cont = sitesList5101.getNemotecnico().size();

    for(int i =0; i<cont; i++){
        tr[i] = new TableRow(this);

        tr[i].addView(nemotecnico[i], new TableRow.LayoutParams(1));
        tr[i].addView(precio[i], new TableRow.LayoutParams(2));
        tr[i].addView(variacion[i], new TableRow.LayoutParams(3));
        tr[i].addView(ttransado[i], new TableRow.LayoutParams(4));
        tr[i].addView(pcierre[i], new TableRow.LayoutParams(5));


        layout.addView(tr[i], new TableLayout.LayoutParams());

    }
}

/*********  AlertDialog *********************************************/
/*********  AlertDialog *********************************************/

  public boolean isOnline(Context c) {
        ConnectivityManager cm = (ConnectivityManager) c
        .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();

        if (ni != null && ni.isConnected())
          return true;
        else
          return false;
        }

    @Override
    protected Dialog onCreateDialog(int id) {
      Dialog dialog = null;
      switch (id) {
      case DIALOG_ERROR_CONNECTION:
        AlertDialog.Builder errorDialog = new AlertDialog.Builder(this);
        errorDialog.setTitle("Problema de Conexión");
        errorDialog.setMessage("No tiene conexión a internet, es necesario para acceder al contenido");
        errorDialog.setNeutralButton("ACEPTAR",
        new DialogInterface.OnClickListener() {


          public void onClick(DialogInterface dialog, int id) {
            finish();
          }
        });

       AlertDialog errorAlert = errorDialog.create();
       return errorAlert;

      default:
        break;
      }
    return dialog;
    }

    /*********  AlertDialog *********************************************/
    /*********  AlertDialog *********************************************/

public void refrescar8(View view){
    Button button = (Button)findViewById(R.id.button1);

    if (!isOnline(this)) {
        if(view==button)
            button.setBackgroundResource(R.drawable.buttonrefresh7);
      showDialog(DIALOG_ERROR_CONNECTION); //displaying the created dialog.
    } else {
        if(view==button)
            button.setBackgroundResource(R.drawable.buttonrefresh7);
    onRestart();
    }
}

@Override
protected void onRestart() {
    // TODO Auto-generated method stub
    super.onRestart();
    Intent i = new Intent(xml5101.this, xml5101.class);
    startActivity(i);
    finish();
}

}

1 个答案:

答案 0 :(得分:0)

如果您关闭GSM,是否有WIFI连接或没有连接到互联网? 如果没有互联网连接,访问URL将失败并抛出异常,您将捕获并打印到stdout。你检查过LogCat输出了吗?