contentResolver无法为大量文件

时间:2016-09-12 14:18:34

标签: android database cursor

好的,我正在建立一个Android音乐应用。我的测试设备有大约500首歌曲。 我正在执行以下操作将音乐文件导入List。

new Thread(new Runnable() {
            @Override
            public void run() {
                if (cursor != null) {
                    count = cursor.getCount();
                    cursor.moveToFirst();
                    while(count > 0) {
                        String name= cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
                        String artist=cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
                        String data = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
                        String albumId=cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
                        Cursor cursor1 = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                                new String[] {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART},
                                MediaStore.Audio.Albums._ID+ "=?",
                                new String[] {String.valueOf(albumId)},
                                null);
                        String image="";
                        if (cursor1.moveToFirst()) {
                            image = cursor1.getString(cursor1.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
                            // do whatever you need to do
                        }

                        //arrayList_Title.add(data);
                        // Toast.makeText(getApplicationContext(),data,Toast.LENGTH_LONG).show();
                        Log.d("lsf", data);

                        musicName.add(name);
                        musicAdd.add(data);
                        musicArtist.add(artist);
                        musicImage.add(image);
                        cursor.moveToNext();
                        count--;
                    }
                    cursor.moveToFirst();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            adapter=new ListViewPopulator(MainActivity.this,musicName,musicAdd,musicArtist,musicImage);
                            recyclerView.setAdapter(adapter);
                        }
                    });

                }
                try {
                    cursor.close();
                } catch (NullPointerException npe) {
                    npe.printStackTrace();
                }
            }

        }).start();

当我运行我的应用时,我收到以下错误:

  

android.database.CursorWindowAllocationException:光标窗口可以   不是用活页夹创建的。

恰好出现在这一行:

  

Cursor cursor1 = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,                                       new String [] {MediaStore.Audio.Albums._ID,MediaStore.Audio.Albums.ALBUM_ART},                                       MediaStore.Audio.Albums._ID +" =?",                                       new String [] {String.valueOf(albumId)},                                       空);

我是否正确地解释了这一点?我的应用程序真的无法为大量的内存分配内存。的文件? 如果有,我有什么选择?

=======

0 个答案:

没有答案