OnActivityResult () will not be called if the call is for the camera

My simple structure is:

  • List.java (activity A)
  • New.java (Activity B)

Steps:

  • Run A and use startActivityForResult() to go to B with the button.
  • Then in B use Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); and startActivityForResult() to take a snapshot of the call camera.
  • After that, onActivityResult() is called in B. Then I press the button to set the result code and close B.

However, B is closed, but onActivityResult() in is never called.

If I skip the step to take a picture, press the button to set the result code and close B. onActivityResult() in A. Will be called successfully.

I just got confused in these two situations. Please tell me why the first situation is happening?

Many thanks.

+7
source share
2 answers

this happened when your first activity is destroyed.

0
source

I tried to reproduce what you are describing, but no luck:

http://androidgecko.com/project.zip

Look and say if I missed something.

Know that when another application comes to the fore (the camera in this case), the android can kill previous processes to free up memory (not even for the operations described in the Google documentation, but the entire PID), which can cause problems.

I have seen this behavior, especially on older phones, when you launch Gallery or Camera apps from within your app.

This is one of the reasons that applications like Facebook have their own Gallery / Camera implementation (so the PID is not killed because it's the first one).

However, even if the PID is killed, you should see the activity, that is, its onCreate with savedInstanceState , which is not null, should fire .. and then onActivityResult ..

check out my example and let me know how I can reproduce your problem.

0
source

All Articles