I have an activity A where you can press a button and choose between selecting a picture from the gallery and taking a new picture. When selecting a picture from the gallery everything is fine and the image is shown in the activity A. If you want to take a new picture, the camera app will be opened, you can take a picture and save it. And now the strange thing happens: instead of returning to the previous activity A from where you choose to take a picture, a new instance of activity A (A') will be created and launched. I don't know why it doesn't return to activity A... Is its possible that activity A got a timeout and that's why a new instance will be created? Or any other ideas why a new instance is created?
Asked
Active
Viewed 513 times
3
-
check this out: http://stackoverflow.com/questions/10411009/activity-killed-oncreate-called-after-taking-picture-via-intent – Pablo Chvx May 03 '14 at 14:11
2 Answers
-1
Use startActivityForResult
to start camera activity. And when you want to come back t prev activity, just use setResult
and call finish()
for current activity.
You might be calling startActivity()
again for activity A, so it was again getting created.
So try this and let me know it solves the problem. :)

Shrikant Ballal
- 7,067
- 7
- 41
- 61
-
In activity A I use startActivityForResult to start the camera. I don't know if I get it wrong, but doesn't the camera app set setResult and call finish? – anel Jun 05 '12 at 13:21
-
Sorry I didn't get you? Are you using default camera or custom camera? – Shrikant Ballal Jun 05 '12 at 13:22
-
Can you post your code? the code that starts camera and calls onActivityResult(). – Shrikant Ballal Jun 05 '12 at 13:25
-
I'm using the default camera. From activity X I launch activity A. When pressing a button I open a chooser (select image from gallery or take a new picture). After choosing "take a new picture" I open the default camera app with startActivityForResult. And after the user took a picture, the camera app finishes and return the image into the onActivityResult. so far so good. my problem is that after the camera app finishes I don't return to activity A but a new instance of activity A is created. – anel Jun 05 '12 at 16:49
-
expected path: X --> A --> camera --> camera finishes --> A with the image in onActivityResult but in my case: X --> A --> camera --> camera finishes --> new instance A' with image in onActivityResult – anel Jun 05 '12 at 16:50