Mj1992
Mj1992

Reputation: 3504

IntentService not called if I put bitmap in Bundle and send to the service

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 ?

Upvotes: 1

Views: 837

Answers (1)

Gunhan
Gunhan

Reputation: 7035

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);

Upvotes: 2

Related Questions