Android 屏幕旋转时执行回调内部的代码

Android 屏幕旋转时执行回调内部的代码,android,Android,当我旋转屏幕时,我在Android的回调中执行了几个代码实例。我总是测试屏幕旋转,因为这种“小车”行为。但今天我想可能我做错了什么,或者这是一个应该向Android项目报告的bug 最新的例子是 我有一个自动完成字段 FindReplaceAutoCompleteAdapter mAutoCompleteAdapter; protected void onCreate(...){ mAutoCompleteAdapter = new FindReplaceAutoCompleteAdap

当我旋转屏幕时,我在Android的回调中执行了几个代码实例。我总是测试屏幕旋转,因为这种“小车”行为。但今天我想可能我做错了什么,或者这是一个应该向Android项目报告的bug

最新的例子是

我有一个自动完成字段

FindReplaceAutoCompleteAdapter mAutoCompleteAdapter;
protected void onCreate(...){
    mAutoCompleteAdapter = new FindReplaceAutoCompleteAdapter(this,
            android.R.layout.simple_dropdown_item_1line);

    mFindRule.setAdapter(mAutoCompleteAdapter);
}
我有适配器

public class FindReplaceAutoCompleteAdapter extends
        ArrayAdapter<FindReplaceRuleContainer> {

    private FindReplaceRuleFilter mFilter = null;

    @Override
    public Filter getFilter() {

        if (mFilter == null)
            mFilter = new FindReplaceRuleFilter();
        return mFilter;
    }

    public FindReplaceAutoCompleteAdapter(Context context,
            int textViewResourceId) {
        super(context, textViewResourceId);
    }

}
公共类findReplaceAutompleteAdapter扩展
阵列适配器{
私有FindReplaceRuleFilter mFilter=null;
@凌驾
公共过滤器getFilter(){
if(mFilter==null)
mFilter=newfindReplaceRuleFilter();
返回过滤器;
}
公共查找替换自动完成适配器(上下文,
int textViewResourceId){
super(上下文,textViewResourceId);
}
}
过滤器呢

public class FindReplaceRuleFilter extends Filter {

    @Override
    protected FilterResults performFiltering(CharSequence constraint) {
        FilterResults fr = null;
        if (constraint != null) {
            List<FindReplaceRuleContainer> list = getFilterdValues(constraint
                    .toString());

            if (list != null) {
                fr = new FilterResults();
                fr.values = list;
                fr.count = list.size();
            }
        }
        return fr;
    }

    private List<FindReplaceRuleContainer> getFilterdValues(String string) {
        List<FindReplaceRuleContainer> lst = Sdbi
                .loadFindReplaceRulesAutoComplete(FindReplaceList.this,
                        string);
        return lst;
    }

    @Override
    protected void publishResults(CharSequence constraint,
            FilterResults results) {
        /**
         * Publish the result to the list activity so it looks pretty.
                     * Instead of a drop-down list
         */
        mAutoCompleteAdapter.clear();
        if( Adapter != null ){ //this is the fix I had to do because 
                     //this code is called even though no filter action was launched
                     //It crashes because the Adapter is reloaded on an AsyncTask that
                     //start onResume() and may not be done by the time this code
                     //inexplicably resides to run
            Adapter.clear();
            if (results != null) { 
            ...
            }
            Adapter.notifyDataSetChanged();
        }
    }

}
公共类FindReplaceRuleFilter扩展了过滤器{
@凌驾
受保护的筛选器结果性能筛选(CharSequence约束){
FilterResults fr=null;
if(约束!=null){
列表=getFilterdValues(约束
.toString());
如果(列表!=null){
fr=新的过滤器结果();
fr.values=列表;
fr.count=list.size();
}
}
返回fr;
}
私有列表getFilterdValues(字符串){
列表lst=Sdbi
.loadFindReplaceRulesAutoComplete(FindReplaceList.this,
字符串);
返回lst;
}
@凌驾
受保护的无效发布结果(CharSequence约束,
FilterResults(结果){
/**
*将结果发布到“列表”活动,使其看起来漂亮。
*而不是下拉列表
*/
mAutoCompleteAdapter.clear();
如果(Adapter!=null){//这是我必须做的修复,因为
//即使未启动筛选操作,也会调用此代码
//它崩溃是因为适配器在异步任务上重新加载
//启动onResume(),在执行此代码时可能无法完成
//莫名其妙地跑
适配器。清除();
如果(结果!=null){
...
}
Adapter.notifyDataSetChanged();
}
}
}
在onResume()之后旋转屏幕时调用publishResults()中的代码。 但屏幕旋转时,甚至不会触摸自动完成字段


这种行为可以在其他UI组件上看到,但我无法记录其他实例。

您找到了吗?我也有同样的问题。