0

I am developing an android application of Image gallery view. So I run a for loop as shown below to get ArrayList of uri string of all jpeg, jpg and png files. So in executing this process it takes around 50-60 secends. ( This for loop is running on AsyncTask). Is there any way I can get the task quicker.

// I am passing Environment.getExternalStorageDirectory() to this function

    public void fileextractor(File raw){
    File[] files = raw.listFiles();
    for(int i=0; i<files.length;i++){

        if(files[i].isDirectory()){fileextractor(files[i]);}
        else {
            IMGS[imageCounter] = (Uri.fromFile(files[i]).toString());
            //IMGS is String[];
            imageCounter++;

        }
    }

}
Ramkrishna Sharma
  • 6,961
  • 3
  • 42
  • 51
Ankesh kumar Jaisansaria
  • 1,563
  • 4
  • 26
  • 44
  • 1
    Using listFiles(FileFilter) would be a bit quicker, it would reduce the number of allocations needed. But the real answer is that you don't need to do this, MediaScanner does it for you. You just need to query the content resolver. http://stackoverflow.com/questions/4195660/get-list-of-photo-galleries-on-android – Gabe Sechan Mar 11 '16 at 20:02
  • Thanks for the solution....this was very helpful – Ankesh kumar Jaisansaria Mar 28 '16 at 08:54
  • After this solution now I am stuck at one point. Please help me overcoming this issue. http://stackoverflow.com/q/36248725/5309039 – Ankesh kumar Jaisansaria Mar 28 '16 at 08:59

0 Answers0