Activity gets killed while executing the camera intent
Posted
by
BlackRider
on Stack Overflow
See other posts from Stack Overflow
or by BlackRider
Published on 2012-03-16T19:57:32Z
Indexed on
2012/03/19
10:03 UTC
Read the original article
Hit count: 256
In my app I call the system camera to take a picture, and then handle the result in onActivityResult
. You know, the usual. It used to work, but now my calling activity gets killed while I'm taking the picture. Specifically, onDestroy()
is called on my activity right after I press the camera shutter. The photo does get taken & saved (I've checked that the file gets written on the SD card). After I accept the photo, instead of returning to the calling activity and invoking onActivityResult
, the previous activity in the activity stack gets called. I see no exceptions in the logcat. My custom exception handler doesn't get called. If it matters, my app also includes a service that listens to GPS updates, but I unregister all the receivers in onPause()
.
Here's the call stack for MyCallingActivity.onDestroy()
:
Thread [<1> main] (Suspended (breakpoint at line 303 in NewPlaceDetailsActivity))
NewPlaceDetailsActivity.onDestroy() line: 303
ActivityThread.performDestroyActivity(IBinder, boolean, int, boolean) line: 2663
ActivityThread.handleDestroyActivity(IBinder, boolean, int, boolean) line: 2694
ActivityThread.access$2100(ActivityThread, IBinder, boolean, int, boolean) line: 117
BinderProxy(ActivityThread$H).handleMessage(Message) line: 968
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 130
ActivityThread.main(String[]) line: 3687
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 842
ZygoteInit.main(String[]) line: 600
NativeStart.main(String[]) line: not available [native method]
This is how I start the camera activity, in case you're wondering:
protected void startCamera() {
createPhotoDirsIfNeeded();
String fileName = "temp.jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
m_capturedImageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
m_photoFileName = APP_PHOTO_PATH + "/" + DateFormat.format(DATE_FORMAT, Calendar.getInstance().getTime()) + ".jpg";
File picFile = new File(m_photoFileName);
if(picFile.exists()) {
picFile.delete();
}
// start the camera activity
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(picFile));
startActivityForResult(intent, IntentHelper.REQUEST_TAKE_PHOTO);
}
How can I find out why does my activity get killed, AND removed from the stack instead of being created again?
© Stack Overflow or respective owner