【发布时间】:2019-05-21 09:56:21
【问题描述】:
我尝试了很多方法来通过相机捕获图像将一个片段传递给另一个片段我尝试了多种方法,但我无法做到,请帮我这样做。
使用意图和共享偏好
应用关闭
【问题讨论】:
-
不传递位图,只传递图像路径。
-
你也可以添加你的代码段
标签: android sharedpreferences android-bitmap
我尝试了很多方法来通过相机捕获图像将一个片段传递给另一个片段我尝试了多种方法,但我无法做到,请帮我这样做。
使用意图和共享偏好
应用关闭
【问题讨论】:
标签: android sharedpreferences android-bitmap
有多种方法可以将对象从一个活动(片段)传递到另一个活动。最适合您的情况是通过 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