I'm sending an intent to the camera from an activity that I call like this:
Intent testphoto = new Intent(Dashboard.this,CameraHandler.class);
startActivity(testphoto);
In the CameraHandler
class I call the camera:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
But before onActivityResult
gets called in the CameraHandler
class the activity is destroyed. Is there anyway to prevent this?
FOUND THE ANSWER:
I had noHistory="true"
in my AndroidManifest
and that made the OS destroy the activity before the result.
Be sure you don't have the "Don't keep activities" Developer setting on, as it will destroy the activity you are leaving.
You don't have to worry about the calling Activity
being destroyed when you call startActivityForResult()
, as it won't change the expected behavior at all (i.e. the child activity will remember to pass the result back to the parent whether the parent is destroyed or not). See this post.
Also note that while it is sometimes necessary to prevent Activity
s from being destroyed (i.e. on configuration changes, etc.), in general you want to leave the Activity
lifecycle alone and let the system manage background Activity
s for you. Once you launch a new Activity
, you shouldn't be explicitly preventing previous Activity
s from being destroyed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With