将位图从一个活动传递到另一个活动时 BINDER TRANSACTION 失败 [英] FAILED BINDER TRANSACTION while passing Bitmap from one activity to another
问题描述
我想将图像作为位图从一个活动传递到另一个活动.我想知道是否可以这样做.
I want to pass a image as a bitmap from one activity to another. And i want to know whether it is possible to do like that.
发送活动
Intent intent = new Intent(getApplicationContext(), BitmapActivity.class);
Bundle b = new Bundle();
b.putParcelable("BITMAP", bitmap);
intent.putExtras(b);
startActivity(intent);
接收活动
Bundle bb = this.getIntent().getExtras();
b = bb.getParcelable("BITMAP");
但我得到了!!!绑定交易失败!!! 错误
推荐答案
您可以使用全局类,其中包含静态位图对象,如下所示:
You can use a global class with a static bitmap object in it, something like this:
public class Global {静态位图 img;}
在通过意图说明活动之前,将您的位图分配给这个全局类属性:
Before stating the activity by intent, assign your bitmap to this Global class attribute:
Global.img = your_bitmap_img;
开始活动后,您可以通过以下方式取回位图:
After starting your activity, you can get back your bitmap by:
bitmap_in_new_activity = Global.img;
我知道全局变量对于调试来说太危险了,但是这种技术可以帮助我们将大量数据从一个活动传输到另一个活动.活页夹事务缓冲区有一个有限的固定大小,无论您的设备功能或应用程序如何,目前都是 1Mb.
I know global variables are too dangerous for debugging but this technique helps us to transfer large data from one activity to another.The binder transaction buffer has a limited fixed size, currently 1Mb regardless of your device capabilities or your app.
这篇关于将位图从一个活动传递到另一个活动时 BINDER TRANSACTION 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!