I have a Spinner with a bunch of state names. In onCreate()
, I set it to a default value. The index 0 in the Spinner array is "Alabama"
String state = "California"; //preset to this
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_state_and_drivers_license);
statesSpinner = (Spinner)findViewById(R.id.states_spinner);
adapter = (ArrayAdapter<String>)statesSpinner.getAdapter();
statesSpinner.setSelection(adapter.getPosition(state));
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, RESULT_CAMERA);
}
However, after onResult, the Spinner is once again set to "Alabama". Meaning it reverts back to index 0 of the array, even though I thought it should keep its existing selected value.
Edit: I put setSelection(position) into onCreate, onResume, and onDestroy. Still, when I return from the camera intent, the spinner still resets and does not go to my selection.