【问题标题】:how to send/save multiple image from one activity to other?如何将多个图像从一个活动发送/保存到另一个活动?
【发布时间】:2014-04-03 06:18:09
【问题描述】:

假设我有四到五张图片,无论是来自相机还是画廊,我所做的那部分。现在 我想让那四五张图片出现在另一个活动中,我该怎么做, 就像您在 olx 应用程序中看到的那样。 谁能帮我解决这个问题。

下面是我的代码:-

 Uri selectedImage = data.getData();
 String[] filePathColumn = { MediaStore.Images.Media.DATA };

 Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
 cursor.moveToFirst();

 int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
 String picturePath = cursor.getString(columnIndex);
 cursor.close();

 SharedPreferences sp = getSharedPreferences("ImageSharedPref", 0); // Open SharedPreferences with name AppSharedPref
 Editor editor = sp.edit();
 editor.putString("picturePath", picturePath); // Store selectedImagePath with key "ImagePath". This key will be then used to retrieve data.         
 editor.commit();

【问题讨论】:

  • 只需保存在应用程序类中,然后从其他活动中使用它..
  • 最好保存在文件中,并将路径发送到下一个Activity。
  • 对这类工作使用 Singleton 类
  • 我没有得到 BhanuSharma 怎么办
  • 正如你在 olx 中看到的,就像我必须做的那样

标签: android image android-camera sharedpreferences image-gallery


【解决方案1】:

将所有图像路径存储在 ArrayList 中>,将此列表传递给意图,并在您的下一个活动中使用列表索引获取所有图像路径。

【讨论】:

  • SharedPreferences sp = getSharedPreferences("ImageSharedPref", 0); // 打开名为 AppSharedPref Editor editor = sp.edit(); 的 SharedPreferences for (int i = 0; i
  • SharedPreferences sp = getSharedPreferences("ImageSharedPref", 0); // 打开名为 AppSharedPref Editor editor = sp.edit(); 的 SharedPreferences for (int i = 0; i
  • 使用 sp.getString("key",false)。因为您在会话中提供一个值,所以不要使用循环。
  • 不,实际上我在数组列表 n 中存储了四个图像路径,我想通过共享首选项向它发送其他活动
  • 使用intent.putExtra("key", arrayList);将图像传递给下一个活动。
【解决方案2】:

将这些图像文件的路径保存在 ArrayList 中。

活动 A:

ArrayList<Uri> myList = new ArrayList<Uri>();

intent.putExtra("pathList", myList);

活动 B:

ArrayList<Uri> myList = (ArrayList<Uri>) getIntent().getSerializableExtra("mylist");

在 Activity B 中获得路径列表后,您始终可以使用 Uri 访问它。

要获取从图库或相机中选择的图像的 Uri:

public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == RESULT_OK) {

     Uri selectedImageUri = data.getData();

【讨论】:

  • 能否请您解释一下,当我从相机或图库中随机拍摄图像时,如何将图像路径保存在数组列表中
  • { if (requestCode == 1) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA };光标 cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]);字符串图片路径 = cursor.getString(columnIndex);光标.close(); myList.add(picturePath);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-04
  • 2012-07-20
  • 2023-03-28
  • 2016-08-18
相关资源
最近更新 更多