Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通过意图发送位图时未启动活动_Android - Fatal编程技术网

Android 通过意图发送位图时未启动活动

Android 通过意图发送位图时未启动活动,android,Android,在我的应用程序中,我正在为当前活动启动一个活动,并通过Intent发送位图,但活动不会启动,当我不发送位图时,它工作正常。代码如下: Intent i = new Intent(A.this, B.class); i.putExtra("USERNAME", userName); i.putExtra("STATUS", status); i.putExtra("IMAGE_BITMAP", bitmap); startActivity(i); 当执行此代码时,活动B未启动,但当我删除i.pu

在我的应用程序中,我正在为当前活动启动一个活动,并通过Intent发送位图,但活动不会启动,当我不发送位图时,它工作正常。代码如下:

Intent i = new Intent(A.this, B.class);
i.putExtra("USERNAME", userName);
i.putExtra("STATUS", status);
i.putExtra("IMAGE_BITMAP", bitmap);
startActivity(i);

当执行此代码时,活动B未启动,但当我删除
i.putExtra(“图像\位图”,位图)时这一行,工作正常。请帮忙。提前感谢。

您需要将其转换为字节数组,然后才能将其添加到应用程序中。这是一个例子

更新:我使用了上面的方法,但我想下面的方法可能更容易使用

更新2:请也查看此评论。这个附加的不是你问题的解决方案,只是一个友好的提醒


我建议您使用
公共静态
全局变量。试试这个

创建一个类

public class Constant  {
  public static Bitmap b = null;
}
现在,当您想将位图从一个活动发送到另一个活动时,请按如下所示使用它

在第一个活动中

Constant.b = bitmap;
Intent i = new Intent(A.this, B.class);
i.putExtra("USERNAME", userName);
i.putExtra("STATUS", status);
startActivity(i);
在第二个活动中

Bitmap b = Constant.b;
img.setImageBitmap(b);  //just for example, use it as per your requirement

它有错误吗?没有,它没有错误。B不在前面吗?是的,B不在前面。我正在工作,但仍然不工作。你能试试第一个吗?我让它运行了很多次。谢谢第一个运行得很好。。。但想知道为什么第二个不起作用吗?是的,我以前不知道位图是“可包裹的”,现在我也很好奇。