I have two activities, activity1 is starting activity2.
in activity 2 I registered an OnFocusChangeListener to a AutoCompleteTextView:
someTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
((AutoCompleteTextView)v).showDropDown();
else
((AutoCompleteTextView)v).dismissDropDown();
}
});
if i write something in the textview and then the activity configuration changes (screen rotate) I get the WindowManager.BadTokenException.
I isolated this to the showDropDown and dismissDropdown methods (by commenting them).
I also tried executing those two methods directly on the Activity’s View object (instead of the one passed through the listener) and got the same exception.
what am I doing wrong ?
When the orientations change the atctivity destory and create again. By this the open list of auto-complete which was create by context of previous activity context will destory as activity is destory. You have to handle orientiaon change your self. So that on rotation activity not destory and auto-complete list view remain same.
Please add This line on your in you AndroidManifest.xml in activity tag.
e.g