0

I want to set my profile image using the camera, but my Activity is killed sometimes when startActivityForResult with ACTION_IMAGE_CAPTURE.

camera run successfully, i can take picture.

but when i press save button after take picture, sometimes my activity is restarted.

How can I solve this problem? Please help me!

Here is my code:

i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, 
           Uri.fromFile(new File(getExternalFilesDir(null).getPath() + "/profile.png")));

startActivityForResult(i, which);

Thank you.

fullyfish
  • 23
  • 4

2 Answers2

0

The reason your activity is being destroyed and recreated is likely because of an orientation change; your app is running in portrait, but the camera is in landscape. When returning to your activity, it first returns in landscape, and recreates itself in portrait (or something along those lines).

You should still be getting the response for the startActivityForResult(), so simply handle the response in onActivityResult(), save the intent in the onSaveInstanceState(), and extract it again in onCreate() with the activity is recreated.

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
  • See also [this related question](http://stackoverflow.com/questions/5279809/trouble-working-with-the-camera-in-onactivityresult?rq=1). – Paul Lammertsma May 11 '13 at 15:23
-2

just call onResume() in onActivityResult. So whenever camera activity completes, your activity will be resumed

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    bitmapImage = (Bitmap) data.getExtras().get("data");
    onResume();
  }