【问题标题】:how to share captured bitmap image(via camera) pass between one fragment two another fragment?如何在一个片段和另一个片段之间共享捕获的位图图像(通过相机)传递?
【发布时间】:2019-05-21 09:56:21
【问题描述】:

我尝试了很多方法来通过相机捕获图像将一个片段传递给另一个片段我尝试了多种方法,但我无法做到,请帮我这样做。

使用意图和共享偏好

应用关闭

【问题讨论】:

  • 不传递位图,只传递图像路径。
  • 你也可以添加你的代码段

标签: android sharedpreferences android-bitmap


【解决方案1】:

有多种方法可以将对象从一个活动(片段)传递到另一个活动。最适合您的情况是通过 Application 类。

创建一个扩展应用程序的类

public class MyApp extends Application {

 public Bitmap myCameraImage;//(or private + getter/setter)

}

然后,在您的 AndroidManifest 中,使用 name 属性添加此类:

<application android:name="<yourpackage>.MyApp"...

现在您可以在每个片段或活动中轻松访问myCameraImage

在片段中访问它:

MyApp myApp = (Myapp) getActivity().getApplication(); myApp.myCameraImage;

在活动中访问它:

MyApp myApp = (Myapp)getApplication(); myApp.myCameraImage;

你可以在一个片段中设置这个值,在另一个片段中访问它

【讨论】:

  • 我猜是这样的:how to share captured bitmap image(via camera) pass between one fragment two another fragment in android
  • @MarcinOrlowski 你会礼貌地告诉你出了什么问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-12
  • 1970-01-01
  • 1970-01-01
  • 2014-01-05
  • 1970-01-01
相关资源
最近更新 更多