在媒体扫描时无法将BpMemoryHeap映射到Android中的Heap

时间:2011-07-18 12:49:40

标签: android listview memory cursor android-mediascanner

我想扫描SD卡中的所有歌曲并将其显示在列表中。

目前我的方法是: -

  1. 创建asyncTask类
  2. 在doInBackground方法中扫描所有媒体文件
  3. 在post post中获取ListView和setCursorAdapter到此ListView
  4. 在我的自定义光标适配器中,我有3种方法: -  4. BindView  5. newView  6. getView(我有onItemClickListener)

    我在这里有两个问题: - 当我的歌曲超过450时,它不会扫描所有歌曲并显示450个列表项

    OnClickListener带来错误 - >无法将BpMemoryHeap映射到堆。 07-18 18:00:56.977:ERROR / JavaBinder(1620): 未捕获的远程异常! (进程之间尚不支持例外。) *

    以下是我的异步任务: -

    私有类FetchAllMusic扩展AsyncTask {         ArrayList跟踪;         光标光标,cursorAlbums;

        @Override
        protected void onPreExecute() {
            myWaitDialog.run();
            super.onPreExecute();
        }
    
        @SuppressWarnings("unchecked")
        @Override
        protected Byte doInBackground(Void... params) {
                String[] projection = { MediaStore.Audio.Media._ID,
                    MediaStore.Audio.Media.ARTIST,          MediaStore.Audio.Media.DATA,
                    MediaStore.Audio.Media.DISPLAY_NAME,
                    MediaStore.Audio.Media.DURATION, MediaStore.Audio.Media.ALBUM,
                    MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.DURATION
                                     };
            String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
         cursor = PlaylistScreen.this.managedQuery(
                    MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,
                    selection, null, null);
            cursor.moveToFirst();
    
              cursorAlbums = null;
                if(cursor.moveToFirst()){
                    do{
                     String[] projection1 = { MediaStore.Audio.Albums.ALBUM_ART };
                        String selection1 = MediaStore.Audio.Albums._ID + " =="
                                + cursor.getString(6);
    
                         cursorAlbums = PlaylistScreen.this.managedQuery(
                                 MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, /* projection */
                projection1, selection1, null, null);
    
                    }while(cursor.moveToNext());
                }
    
                return null;
        }
    
         protected void onPostExecute(Byte result) {
    
            myWaitDialog.dismiss();
            layoutAllMusic = (LinearLayout) findViewById(R.id.l_all_music);
            try{
            Comparator comparator = Collections.reverseOrder();
                System.out.println(tracks);
                    //Collections.sort(tracks, comparator);
                    }catch(Exception e){
    
                e.printStackTrace();
            }
        Log.d("Before List Adapter","+++++++++++++++++");
          PlaylistScreen.this.lv = getListView();
    
    
        MusicCursorAdapter musicCursor = new MusicCursorAdapter(PlaylistScreen.this, cursor, cursorAlbums);
           PlaylistScreen.this.lv.setAdapter(musicCursor);
          super.onPostExecute(result);
        }
    }
    

1 个答案:

答案 0 :(得分:0)

确保关闭所有使用的游标....

cursor = PlaylistScreen.this.managedQuery(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,
            selection, null, null);
    cursor.moveToFirst();

      cursorAlbums = null;
        if(cursor.moveToFirst()){
            do{
             String[] projection1 = { MediaStore.Audio.Albums.ALBUM_ART };
                String selection1 = MediaStore.Audio.Albums._ID + " =="
                        + cursor.getString(6);

                 cursorAlbums = PlaylistScreen.this.managedQuery(
                         MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, /* projection */
        projection1, selection1, null, null);

            }while(cursor.moveToNext());
        }
        cursor.close();
        return null;

再次尝试关闭其他两个游标(musicCursor,cursorAlbums)。希望它能正常工作。