title: How do Gallery app load Images and Videos so fast?
body: <p>I am trying to load all the Images and Videos present on the user's device but the problem is that on some device the loading is very slow and takes some time. And also the loading speed is further decreased if the phone is running many apps at the same time. Whereas the gallery app which is preinstalled loads the Images and Videos at much faster speed (at all times).</p>
  
  <p>This is how I am loading the Images and Videos-</p>
  
  <pre><code>public void getImages(Context context) {
  
          File Image_File;
          final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};
  
          String orderBy = MediaStore.Images.Media.DATE_MODIFIED ;
  
          Cursor cursor = context.getContentResolver().query(
                  MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
                  null, orderBy);
  
          if (cursor != null)
          {
              cursor.moveToFirst();
              final int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
  
              while (cursor.moveToNext()) 
               {
                  Image_File = new File(cursor.getString(dataColumnIndex));
                              images.add(0,Image_File);
  
                }
           }
  }
  
      public void getVideos(Context context) {
  
          File Video_File;
  
          final String[] columns = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID };
          String orderBy =  MediaStore.Video.Media.DATE_MODIFIED;
  
          Cursor cursor = context.getContentResolver().query(
                  MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns, null,
                  null, orderBy);
  
          if (cursor!=null)
          {
              cursor.moveToFirst();
  
              final int dataColumnIndex = cursor.getColumnIndex(MediaStore.Video.Media.DATA);
  
              while (cursor.moveToNext()) {
                  Video_File = new File(cursor.getString(dataColumnIndex));
  
                              videos.add(0,Video_File);
  
              }
          }
      }
  </code></pre>
  
  <p>Any suggestion on how to improve the speed of loading or any suggestion on how to make this code more efficient would be really appreciated and grateful</p>