【问题标题】:Android:Problem in passing image and its URI between two activitiesAndroid:在两个活动之间传递图像及其URI的问题
【发布时间】:2011-08-03 05:09:31
【问题描述】:

我们可以使用 bundle 将图像和图像 URI 传递给同一应用程序中的其他活动吗?建议我采取一些方法吗?

用法:实际上我做了一个活动,裁剪从相机拍摄的图像或从存储在 SD 卡中的图像取决于用户。 和另一个使用背景图片和边框图片的应用程序都被覆盖以便看到PHOTOFRAME

所以现在我想合并这两个应用程序,以便来自第一个应用程序的裁剪图像应该成为第二个应用程序的背景图像。即来自 photoframe。我该怎么做?

【问题讨论】:

标签: android android-2.2-froyo


【解决方案1】:

将图像保存到 SD 卡后

使用它来调用其他活动。

final Intent intent = new Intent(MyClass.this, TargetClass.class);
final String root = Environment.getExternalStorageDirectory().getAbsolutePath();
intent.setData(Uri.parse(root + "/my/image/path/image.png"));
startActivity(intent);

如果你是接收者,那么你可以通过调用获得路径

Uri path = getIntent().getData();

在接收活动的 onCreate 中。这是其他活动检查路径的标准方法。

【讨论】:

    【解决方案2】:

    是的,你可以传递URI对象,见http://developer.android.com/reference/android/os/Bundle.html中的putParcelable方法,URI已经实现了Parcelable接口,你可以使用相应的get方法来获取它。如果任何对象实现了Parcelable接口,那么我们可以使用Bundle传递它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-30
      • 2017-08-05
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      • 2012-10-06
      • 2015-03-10
      相关资源
      最近更新 更多