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.