从摄像机返回结果时也会调用onCreate方法

时间:2011-11-28 11:05:48

标签: android

我正在创建一个可以从相机拍照并在ImageView中加载它的应用程序。 现在我的问题是当我打开相机,拍照并返回我的应用程序,然后 在调用onActivityResult之后,也会调用onCreate方法。

这个问题出现在三星的模型中。当我在HTC Wildfire上运行此代码时,一切正常。在HTC Wildfire中调用onActivityResult然后调用onResume。所以我想要什么 可以在HTC Wildfire中实现,但不能在Samsung S中实现。

这是我的代码,

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

以下是调用相机拍照的代码。

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

相同的代码在HTC中运行良好但在三星中没有运行。

1 个答案:

答案 0 :(得分:1)

也许你的应用程序已被系统杀死,因为拍照时内存不足。然后,活动生命周期将以onCreate()

重新开始