Android Startcamera Gives Me Null Intent and ... Does It Destroy My Global Variable

Android startCamera gives me null Intent and ... does it destroy my global variable?

It's possible that launching of ACTION_IMAGE_CAPTURE will push your activity out of memory. You should check (I'd simply a log, debugger may have its own side effects) that onCreate() of your activity is called before onActivityResult(). If this is the case, you should prepare your activity to reinitialize itself, probably using onSaveInstanceState(Bundle).

Note that the decision whether to shut down the activity, or keep it in background, depends on the overall system state that is beyond your control. It won't surprise me if the decision when you take the first picture, is "shut him down!", but when you take picture again, it is "keep him in background".

Launching a camera in onCreate causing an intermittent issue

Your situation is similar to what happens often when ACTION_IMAGE_CAPTURE intent is launched (see e.g. Android startCamera gives me null Intent and ... does it destroy my global variable?).

The cause is that the system may decide to destroy the caller activity (in your case, the SinglePhotoViewActivity), and recreate it again after the launched activity (in your case, system Camera activity) returns the result.

The ultimate fix involves implementing onSaveInstanceState(Bundle) in the calling activity. But in your specific situation, there is a shortcut. Check the intent in onCreate(), and if it comes from the MainActivity, then launch Camera. Else, proceed as if you are going to receive onActivityResult() right now.

Camera picture returning null url. (Android)

Your activity could have been destroyed by the system to free memory for the Camera app to handle your intent. You can save and the state with onSaveInstanceState() and restore it in onCreate(). See e.g. Android startCamera gives me null Intent and ... does it destroy my global variable?.



Related Topics



Leave a reply



Submit