i'm working on an app to load an amount of images from SD card using AsyncTask + for loop, I've test the app on my Galaxy Nexus, the app working perfectly, but it will crash if i use more than 33 loop

my question is: is there a limitation for using AsyncTask???,,, is there any thing wrong in my code cause the crash over 33 loops?

please help, here is my code:

ImageView iv;
TextView tv;
String picsDir;
int picsAmount;
String [] list;File dir;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //images folder
    picsDir = Environment.getExternalStorageDirectory().toString()+"/aFolder";

    // total images 
    picsAmount = 70;

    iv = (ImageView)findViewById(R.id.iv);
    tv = (TextView)findViewById(R.id.tv);

    list = new String [picsAmount];
    dir = new File (picsDir);           

    // String array of my images names
    list = dir.list();

    new loadingImgs().execute(list);
}

class loadingImgs extends AsyncTask<String, Void, Drawable>{

    @Override
    protected void onPreExecute() {
        // nothing
        super.onPreExecute();
    }

    @Override
    protected Drawable doInBackground(String... params) {

        String dir1 = Environment.getExternalStorageDirectory().toString()+"/aFolder";

        String[] theList = params;
        Bitmap[] bmp = new Bitmap[picsAmount];
        Drawable[] drw = new Drawable[picsAmount];

        tv.setText("dir1="+dir1+"  found= "+picsAmount);            
        File dir = new File(dir1);          



        for (int i = 0; i < picsAmount; i++){
            bmp[i] = BitmapFactory.decodeFile(dir+"/"+theList[i]);
            drw[i] = new BitmapDrawable(getResources(), bmp[i]);        
        }           

        return drw[0];
    }

    protected void onPostExecute(Drawable result) {

        // set drw[0] as iv image
        iv.setImageDrawable(result);


        };

}

}

Related posts

Recent Viewed