3

I am making an application that can take picture from camera and load it in ImageView. Now my problem is when i open a camera, take picture and return back to my app, then onCreate method is also called then after onActivityResult is called.

This problem arise in Samsung s model.When i ran this code on HTC Wildfire everything works fine.In HTC Wildfire onActivityResult is called and then onResume is called.So what i want to achieve is possible in HTC Wildfire but not in Samsung S.

Here is my Code,

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

         Drawable drawable = null;
         System.out.println("Faces Fond"+facesFound);
         System.out.println("On Activity Result is called");
        switch (requestCode) {

        case Constants.PICK_IMAGE:
            switch(resultCode)
            {
            case RESULT_CANCELED:
                break;
            case RESULT_OK:
                dragLayer.removeAllViews();
                isFaceDetected = false;
                resetArray();
                numberOfViews = 0;
                if(data!=null){
                 uriOfImage = data.getData();
                 System.out.println("Uri is "+ uriOfImage);
                 if(bitmapForDragLayer != null)
                 bitmapForDragLayer.recycle();
                    try {
                        bitmapForDragLayer = BitmapFactory.decodeStream(getContentResolver().openInputStream(uriOfImage));
                         bitmapForDragLayer = Bitmap.createScaledBitmap(bitmapForDragLayer, widthOfBitmap, heightOfBitmap, true);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    catch(Exception e){
                        e.printStackTrace();
                    }
                     drawable = new BitmapDrawable(bitmapForDragLayer);
                    dragLayer.setBackgroundDrawable(drawable);
                    isImageLoaded = false;
                    }
                break;
            }
                break;

        case Constants.TAKE_PICTURE_CODE:
            switch(resultCode)
            {
            case RESULT_CANCELED:
                break;
            case RESULT_OK:
                dragLayer.removeAllViews();
                isFaceDetected = false;
                resetArray();
                numberOfViews = 0;
                System.out.println("Value of data"+data);
                if(data!=null){
                bitmapForDragLayer = (Bitmap)data.getExtras().get("data");
                 bitmapForDragLayer = Bitmap.createScaledBitmap(bitmapForDragLayer, widthOfBitmap, heightOfBitmap, true);
                  drawable = new BitmapDrawable(bitmapForDragLayer);
                 dragLayer.setBackgroundDrawable(drawable);
                 isImageLoaded = false;
                }
                 break;
            }
            break;

        case Constants.FRAME_SELECT_CODE:
            currentFrame = frameSelection.getFrameBitmap(resultCode);
            currentSelectedBitmapVO.setSelectedBitmap(selectedFrame);
            selectedFrame = currentFrame;
                    for(int i=0;i<array.size();i++)
                    {
                        System.out.println("value of i"+i);
                        if(array.get(i))
                        {
                        int height = currentBitmapVO[i].getSelectedBitmapHeight();
                        int width  = currentBitmapVO[i].getSelectedBitmapWidth();
                        Bitmap b = Bitmap.createScaledBitmap(currentFrame, width, height, true);
                        selectedFrame = b;
                        imageView[i].setImageBitmap(selectedFrame);
                        imageView[i].invalidate();
                        }
                    }
                break;
        }
 }

Here is the code for calling Camera for taking picture.

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, Constants.TAKE_PICTURE_CODE);

Same code running fine in HTC but not in Samsung.

Pankit
  • 163
  • 9
  • How your activity handle configuration change? – QuickNick Nov 28 '11 at 12:37
  • Take a look on this post: http://stackoverflow.com/questions/4901752/android-2-2-sdk-droid-x-camera-activity-doesnt-finish-properly/8679892#8679892 I solved the question about additional calls to onCreate function with an ugly workaround. – Neonigma Dec 30 '11 at 13:53

1 Answers1

1

Maybe your app has been killed by the system because of low memory when taking the picture. Then the activities lifecycle will start again with onCreate()

fab
  • 1,839
  • 15
  • 21
  • But this code is working fine in HTC Wildfire which has low processor and Samsung S has a higher processor than HTC Wildfire. – Pankit Nov 28 '11 at 11:42
  • I check the logCat and i found that onCreate and onResume is called two times and onActivityResult is called once.The sequence is as follows. 1.onCreate 2.onActivityResult 3.onResume 4.onCreate 5.onResume. – Pankit Nov 28 '11 at 12:12
  • @Pankit, I hat the same problem. this is what you are looking for: http://stackoverflow.com/questions/10411009/activity-killed-oncreate-called-after-taking-picture-via-intent – Cookienator Sep 01 '15 at 13:10