1

I am trying to send a bundle to the service. This is how I am calling the service.

1)    Bundle bundle = new Bundle();
2)    bundle.putParcelable("bitmap", bmp);       //    <--- problem
3)    bundle.putString("type", "SingleImage");

4)    Intent intent = new Intent(getApplicationContext(),SyncService.class);
5)    intent.putExtra("imageUploadBundle", bundle);
6)    startService(intent);

When I comment line 2 the service gets called . But if I do not comment the line the service doesn't gets called. I want to send a bitmap to the service which I will upload to the server. How can I send a bitmap to the service ? and what is causing this problem ?

Mj1992
  • 3,404
  • 13
  • 63
  • 102

1 Answers1

2

Try sending its row byte array like this.

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

Bundle bundle = new Bundle();
bundle.putByteArray("bitmap", byteArray);
bundle.putString("type", "SingleImage");

Intent intent = new Intent(getApplicationContext(),SyncService.class);
intent.putExtra("imageUploadBundle", bundle);
startService(intent);
Gunhan
  • 6,807
  • 3
  • 43
  • 37