Reputation: 137
In my app, I am starting an Activity for current Activity and sending Bitmap through Intent but Activity will not start and when I am not sending that Bitmap it is working fine. Here is the code:
Intent i = new Intent(A.this, B.class);
i.putExtra("USERNAME", userName);
i.putExtra("STATUS", status);
i.putExtra("IMAGE_BITMAP", bitmap);
startActivity(i);
When is execute this code activity B is not starting but when i remove i.putExtra("IMAGE_BITMAP", bitmap);
this line, it works fine. Please help. Thanks in advance.
Upvotes: 1
Views: 785
Reputation: 3676
I suggest you to use public static
global variable for that. Try this
Create one class
public class Constant {
public static Bitmap b = null;
}
Now when you want to send Bitmap from one activity to other, use it as below.
In first activity,
Constant.b = bitmap;
Intent i = new Intent(A.this, B.class);
i.putExtra("USERNAME", userName);
i.putExtra("STATUS", status);
startActivity(i);
In second activity.
Bitmap b = Constant.b;
img.setImageBitmap(b); //just for example, use it as per your requirement
Upvotes: 2
Reputation: 3022
You need to convert it to a Byte array before you add it to the intent. Here is the example
https://stackoverflow.com/a/11010565/655987
Update: I was using the method above but the following might be easier to use I guess
How can I pass a Bitmap object from one activity to another
Update2: Please look at this comment, too. This additional one is not a solution to your problem, but just a friendly reminder
How can I pass a Bitmap object from one activity to another
Upvotes: 0