错误
我尝试使用:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + file_to_open), "image/*");
context.startActivity(intent);
或
Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(file_to_open)),"image/jpeg");
context.startActivity(intent);
它是有效的,但当我尝试离开图像查看意图时,我会收到RuntimeException,StaleDataException试图在光标关闭后访问它
当我尝试启动一个不同的意图时,它是有效的,所以它与暂停或恢复我的活动无关
请有人帮
事实证明,它也是其他意图,比如电子邮件意图,当被取消时,会导致
找到了答案。它与意图本身无关,但与我使用以下方法的事实有关:
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
@SuppressWarnings("deprecation")
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
cursor = null;
return path;
}
请注意,managedQuery已被弃用,即使您决定使用它,也不应该关闭光标或将其设置为null如以下答案所示:
无法恢复活动错误