直到我在android中重新启动设备,光标才会刷新

时间:2021-12-29 01:32:23

I'm developing camera app now and can record videos in app folder successfully. Btw when I read videos from app folder with Cursor, it doesn't refresh cursor. (It means when I record video with app and whenever I want to view videos via app, it shows old videos. even when I close app and re-open app it shows old videos. )

我现在正在开发camera app,可以在app文件夹中成功录制视频。顺便说一句,当我用光标从app文件夹中读取视频时,它不会刷新光标。(它的意思是当我用app录制视频时,当我想通过app观看视频时,它就会显示旧视频。甚至当我关闭应用程序并重新打开应用程序时,它也会显示旧的视频。

Here's source code.

这是源代码。

public static List<MyVideo> getAppVideos(Context context) {
    final String[] projection = { MediaStore.Video.Media.DATA, MediaStore.Video.Media.DATE_TAKEN, MediaStore.Video.Media.DURATION};
    final String selection = MediaStore.Images.Media.BUCKET_ID + " = ?";
    final String[] selectionArgs = { APP_VIDEO_BUCKET_ID };
    final Cursor cursor = context.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            projection,
            selection,
            selectionArgs,
            null);
    ArrayList<MyVideo> result = new ArrayList<MyVideo>(cursor.getCount());
    if (cursor.moveToFirst()) {
        final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
        final int dateColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_TAKEN);
        final int durationColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION);
        do {
            final String data = cursor.getString(dataColumn);
            final String createdDate = cursor.getString(dateColumn);
            final String durationTime = cursor.getString(durationColumn);
            result.add(new MyVideo(data, DateUtils.convertToSeconds(durationTime), "^ " +  DateUtils.getDateFromMilliSeconds(Long.parseLong(createdDate), "MMM dd, yyyy")));

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


}

Could anyone please suggest solution?

谁能提出解决方案吗?

1 个解决方案

#1


1  

If CursorDemo extends CursorAdapter, then you have to use adapter.swapCursor(cursor_update);

如果CursorDemo扩展了CursorAdapter,那么您必须使用adapter.swapCursor(cursor_update);

That should swap the old cursor out for the new one and reload the data. With swapCursor,since the old cursor is not closed.

这应该将旧的游标替换为新的游标,并重新加载数据。使用swapCursor,因为旧的游标没有关闭。

#1


1  

If CursorDemo extends CursorAdapter, then you have to use adapter.swapCursor(cursor_update);

如果CursorDemo扩展了CursorAdapter,那么您必须使用adapter.swapCursor(cursor_update);

That should swap the old cursor out for the new one and reload the data. With swapCursor,since the old cursor is not closed.

这应该将旧的游标替换为新的游标,并重新加载数据。使用swapCursor,因为旧的游标没有关闭。