Reputation: 15078
Hi i have used SurfaceView and taking picture by below code
First i am starting activity by this code
startActivityForResult(new Intent(PictureEditor.this, CustomCamera.class), CAMERA_REQUEST3);
and then getting result from this code
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == CAMERA_REQUEST3) {
BitmapFactory.Options abc = new BitmapFactory.Options();
abc.inJustDecodeBounds = true;
BitmapFactory.decodeFile((Environment.getExternalStorageDirectory() + File.separator + "tester.png"), abc);
abc.inSampleSize = calculateInSampleSize(abc, w, h) + 1;
abc.inJustDecodeBounds = false;
view.setBackBitmap(BitmapFactory.decodeFile((Environment.getExternalStorageDirectory() + File.separator + "tester.png"), abc));
}
Now the CustomeCamera Class's code is below
// / Handles when mTakePicture is clicked
private OnClickListener mTakePictureAction = new OnClickListener() {
@Override
public void onClick(View v) {
if (mCamera != null)
mCamera.takePicture(CustomCamera.this);
}
};
Then
@Override
public void takePicture(Activity activity) {
if (mCamera != null)
mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
Intent returnIntent = new Intent();
activity.setResult(mActivity.RESULT_OK, returnIntent);
activity.finish();
}
the problem is image is captured but the activity is not getting finish! Can anybody suggest me what to do!
Upvotes: 1
Views: 238
Reputation: 56925
you need to write code for finish activity in onActivityResult() in previous activity from where this activity starts.
So your previous activity finish . . .
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode)
{
case YOUR_REQUEST_CODE:
finish();
}
}
Edit :
First change this code.
Intent returnIntent = new Intent();
activity.setResult(Activity.RESULT_OK, returnIntent);
activity.finish();
then in onActivityResult() first check the request code condition then after in request code condition check result code condition.
Upvotes: 3
Reputation: 1309
I have a strong feeling that main (UI) thread is stuck while
@Override
public void takePicture(Activity activity) {
if (mCamera != null)
mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
Intent returnIntent = new Intent();
activity.setResult(mActivity.RESULT_OK, returnIntent);
activity.finish();
}
I am not too sure where it is being stuck (from code example above), possibilities
1) picture cannot be saved
2) picture cannot be encoded
and etc
You can test it by running debugger
Upvotes: 0