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
How to Get an Event in Android Spinner When the Current Selected Item Is Selected Again
Android Mediaplayer Error (1, -2147483648)
Create a Ninepatch/Ninepatchdrawable in Runtime
Open an Image Using Uri in Android's Default Gallery Image Viewer
Android: Speech Recognition Without Using Google Server
Getexternalstoragepublicdirectory Deprecated in Android Q
Apply a Theme to an Activity in Android
Sharing Data Between Fragments Using New Architecture Component Viewmodel
How to Create Text File and Insert Data to That File on Android
Error Message 'Java.Net.Socketexception: Socket Failed: Eacces (Permission Denied)'
Android Set Up Volley to Use from Cache
Handle Screen Rotation Without Losing Data - Android
Android Textwatcher.Aftertextchanged VS Textwatcher.Ontextchanged
Gradle - Library Duplicates in Dependencies
Get All User Friends Using Facebook Graph API - Android