StartActivityForResult - question
I have an activity "QueryInput" with textviews in it, which can call another activity "QueryInputHistory" with startActivityForResult.
However tj开发者_如何学Ce entries in the textviews of the activity "QueryInput" are not saved (to be more precised, they are deleted just before the other activity is called).
Can I somehow prevent that?
If I am understanding, you would like the entries in a textView, not an editText, to persist when the user returns from QueryInputHistory back to the QueryInput activity. The text state of any editText with a valid resource ID is automagically persisted by the Android OS on a soft kill, but the text state of a textView is NOT guaranteed to be automagically persisted on a soft kill. So any non-view instance values AND any state of textView will need to be saved programmatically, perhaps in onSaveInstanceState or in onRetainConfigurationState on a soft kill and to prefs in OnStop or in onDestroy on a hard kill, if that is consistent with your requirements.
A workaround might be to use a disabled editText:
if (cbProhibitEditPW.isChecked()) { // disable editing password
editTextPassword.setFocusable(false);
editTextPassword.setFocusableInTouchMode(false); // user touches widget on phone with touch screen
editTextPassword.setClickable(false); // user navigates with wheel and selects widget
isProhibitEditPassword= true;
}
else { // enable editing of password
editTextPassword.setFocusable(true);
editTextPassword.setFocusableInTouchMode(true);
editTextPassword.setClickable(true);
isProhibitEditPassword= false;
}
精彩评论