我正在尝试访问活动中捕获的另一个活动(比如说B)中的图像(比如A)。现在,我有两个选择:
1. Save to sd card and then access in activity B through the filepath.
But, time taken to save is higher in some cases, probably because of higher
image size.
2. Send the bit array through intent.putExtra("imageArray" , data) and access it
in activity B through getIntent(). But on surfing net, I found sending bigger
bitmap of 1MB or more is a bad practise but didn't find anything with regards to
bitarray.
有人可以建议我哪个选项更好吗?并且发送一个更大尺寸的位图作为bitArray到另一个活动是一个坏习惯吗?
我的要求是:两个活动A和B之间的时间间隔应该是最小的。此外,图像应立即加载到活动B中。
提前致谢。
答案 0 :(得分:1)
如果您使用网址在活动A和活动B中加载图片,则可以使用离子 - https://github.com/koush/ion。它可以帮助您使用URL显示图片并缓存您的图像,以便立即再次加载它,只需将活动A中的URL发送到活动B.
如果您使用手机摄像头捕捉图像,我会说保存它是更好的方法,如果您想要在未来一次发送许多图片,第二个选项将会很糟糕。
答案 1 :(得分:1)
您还可以在应用程序空间(单例)中使用全局变量。
示例:
public class YourApplication extends Application
{
private static YourApplication singleton;
Bitmap bitmap; // or any type, byte array
....
public static YourApplication getInstance()
{
return singleton;
}
}
...
在另一个课程中,您可以设置并获取此变量'位图':
YourApplication.getInstance().bitmap = ....; // in Activity A
或
... = YourApplication.getInstance().bitmap; // in Activity B
或在另一种方法中使用
....( ..., YourApplication.getInstance().bitmap, ...);