I’m developing an Android application that uses a Fragment that will launch the camera with an Intent to capture an image and then the fragment also contains some EditText‘s for the user to fill in when the Intent returns.
I wonder what the best place (best practice) to launch the intent is? Is it in the onCreate() or the onCreateView() method that are both overridden?
As CommonsWare stated in the first comment a fragment should not be starting an
Activityfrom neither ofonCreatenoronCreateView. His argument was that since the user didn’t press a button, no action should be taken. In my design however, an"Add"button had been pressed that then launched the fragment which I wanted to automatically launch the camera intent. My reason for doing this was to force the user into first take a picture since my application requires a picture to work. The user would then fill out some other fields and save the data.I realize now that CommonsWare was right. It is better to let the user click another button then to surprise them into something they didn’t expect. I also realized that it is a good idea to let the user see what fields are required in the form before forcing the user to take an action.
I ended up adding an
ImageButtonwith the camera icon to launch the intent and it’s working great.