0

Possible Duplicate:
How can I pass a Bitmap object from 1 activity to another

i am using a camera application in android. in my application im tried to pass the image that clicked to another activity. code as shown bellow,

 PictureCallback jpegCallback = new PictureCallback() 
    {
        public void onPictureTaken(byte[] data, Camera camera) 
        {
               Intent i = new Intent(Hackbook.this, view.class);
                   i.putExtra("photo", data);
                   Log.d(TAG, "jpegCallback1" +data);
                  startActivity(i); 
        }
    };

and second activity view.java is,

setContentView(R.layout.view);
        Bundle extras = getIntent().getExtras();
        byte[] photo = extras.getByteArray("photo");
        Log.i(TAG, "jpegCallback2" + photo);
        Bitmap bitmap  = BitmapFactory.decodeByteArray (photo, 0, photo.length);
        ImageView imgView = (ImageView)findViewById(R.id.photoResultView);
        imgView.setImageBitmap(bitmap); 

when i run this in emulator i got an image that inbuilt in the emulator. But when im tried to run this in my device there is no image displayed in the second activity. Logcat is shown bellow,

12-14 17:58:33.756: DEBUG/camera(630): jpegCallback1[B@44f90d60
12-14 17:58:33.785: INFO/ActivityManager(58): Starting activity: Intent { cmp=com.facebook.android/.view (has extras) }
12-14 17:58:33.985: INFO/Camera(630): jpegCallback2[B@44f385e0
12-14 17:58:34.605: INFO/ActivityManager(58): Displayed activity com.facebook.android/.view: 730 ms (total 730 ms)
12-14 18:00:56.351: DEBUG/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol

If anyone know about this please help me....

Community
  • 1
  • 1
Binesh
  • 117
  • 3
  • 15

2 Answers2

0
possible duplicate answer

try to pass bitmap object using intent object like this way

Intent i = new Intent(Hackbook.this, view.class);
Bitmap bitmap  = BitmapFactory.decodeByteArray (data, 0, photo.length);
i.putExtra("BitmapImage", bitmap);
startActivity(i);

and retrieve time do this way

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");

see this post https://stackoverflow.com/a/2459624/760489

Community
  • 1
  • 1
Pratik
  • 30,639
  • 18
  • 84
  • 159
0

You can simply name you Bitmap as static first.

 public static Bitmap bitmap;

then create a method like this in First Activity

public static Bitmap getBitmap(){
   return bitmap;
}

and call that function where you required( In other Activities)

bitmap_requiredclassname.getBitmap();
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166