0

我刚买了三星 Galaxy S3,还有 HTC Desire S。我的应用程序几乎完成了,它在 HTC Desire S 上运行良好。问题在于我的 S3 - 执行任务时出现内存不足错误。它第一次通过,但每次下一次执行都会使应用程序崩溃(由于错误-12,无法分配大小为 2097152 的 cursorWindow(数据库/baza ....))

我的线程:

  private class nalozi_statistiko_igralca extends AsyncTask<Void, Integer, Void> {

  protected Void doInBackground( Void... ignoredParams ) {

      publishProgress();
      vpisi_statistiko_igralca_update();
        cursor_statistika_igralca_tocke = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_domaci_kopija+ " ORDER BY tocke DESC", null);

        cursor_statistika_igralca_tocke_gosti = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_gosti_kopija+" ORDER BY tocke DESC", null);


        cursor_statistika_igralca_asistence = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_domaci_kopija+ " ORDER BY asistence DESC", null);

        cursor_statistika_igralca_asistence_gosti = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_gosti_kopija+ " ORDER BY asistence DESC", null);


        cursor_statistika_igralca_obrambni_skoki = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_domaci_kopija+ " ORDER BY defensive_rebounds DESC", null);

        cursor_statistika_igralca_obrambni_skoki_gosti = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_gosti_kopija+ " ORDER BY defensive_rebounds DESC", null);


        cursor_statistika_igralca_napadalni_skoki = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_domaci_kopija+ " ORDER BY offensive_rebounds DESC", null);

        cursor_statistika_igralca_napadalni_skoki_gosti = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_gosti_kopija+ " ORDER BY offensive_rebounds DESC", null);


        cursor_statistika_igralca_ukradene_zoge = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_domaci_kopija+ " ORDER BY steals DESC", null);

        cursor_statistika_igralca_ukradene_zoge_gosti = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_gosti_kopija+ " ORDER BY steals DESC", null);


        cursor_statistika_igralca_blokade = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_domaci_kopija+ " ORDER BY blocks DESC", null);

        cursor_statistika_igralca_blokade_gosti = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_gosti_kopija+ " ORDER BY blocks DESC", null);


        cursor_statistika_igralca_izgubljene_zoge = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_domaci_kopija+ " ORDER BY turnovers DESC", null);

        cursor_statistika_igralca_izgubljene_zoge_gosti = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_gosti_kopija+ " ORDER BY turnovers DESC", null);


        cursor_statistika_igralca_osebne = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_domaci_kopija+ " ORDER BY fouls DESC", null);

        cursor_statistika_igralca_osebne_gosti = baza5.rawQuery("SELECT * FROM player_stats" +
                " WHERE id_seznam_iger LIKE "+id_seznam_iger+ " AND id_ekipe LIKE "+ id_izbrane_ekipe_gosti_kopija+ " ORDER BY fouls DESC", null);

             return null; 
  }

  protected void onPostExecute( Void array )
  {
    if(nalozi_statistiko_igralca_ali_upload==0)
    {
      pokazi_statistiko_igralca(view);
      pokazi_statistiko_igralca_tocke2(view);
    }
    if(nalozi_statistiko_igralca_ali_upload==1)
    {
        naredi_pdf_izvrsi(view);
    }
    if(nalozi_statistiko_igralca_ali_upload==2)
    {
        pokazi_mvp_domaci(domaci_top_efficiency_id);
    }
    if(nalozi_statistiko_igralca_ali_upload==3)
    {
        pokazi_mvp_gosti(gosti_top_efficiency_id);
    }
  }

  protected void onProgressUpdate(Integer... values)
  {
      Context context = getApplicationContext();
      int duration = Toast.LENGTH_SHORT;
      Toast toast = Toast.makeText(context,  getString(R.string.toast_loading), duration);
      toast.show();


    }

}

public void vpisi_statistiko_igralca_update()
{
    Cursor cursor_ekipa_domaci;

    //list_home = (ListView) findViewById (R.id.list_home);
    //cursor2 = baza5.query("igralci", null, null, null, null, null,"_id" + " ASC");
    cursor_ekipa_domaci = baza5.query("igralci_kopija",null, 
            "id_ekipe like " + id_izbrane_ekipe_domaci_kopija,
            null, null, null, null);


    while (cursor_ekipa_domaci.moveToNext())
    {
        String a=cursor_ekipa_domaci.getString(0);
        update_statistiko_igralca((Integer.valueOf(a)),
                cursor_ekipa_domaci.getString(1),
                cursor_ekipa_domaci.getString(2));
    }

    Cursor cursor_ekipa_gosti;

    //list_home = (ListView) findViewById (R.id.list_home);
    //cursor2 = baza5.query("igralci", null, null, null, null, null,"_id" + " ASC");
    cursor_ekipa_gosti = baza5.query("igralci_kopija",null, 
            "id_ekipe like " + id_izbrane_ekipe_gosti_kopija,
            null, null, null, null);
    while (cursor_ekipa_gosti.moveToNext())
    {
        String a=cursor_ekipa_gosti.getString(0);
        update_statistiko_igralca((Integer.valueOf(a)),
                cursor_ekipa_gosti.getString(1),
                cursor_ekipa_gosti.getString(2));
    }
}

繁重的工作在函数“vpisi_statistiko_igralca_update”中完成。我想知道 Galaxy S3 是否将数据保存在内存中,但 HTC Desire S 不...

4

1 回答 1

0

我想通了!!

当我不再需要它们时,我需要关闭我的光标。(我需要关闭大约 100 个不同的游标)。

(cursor.close());

于 2013-02-08T13:31:22.350 回答