{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/4971","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/4971/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/4971/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/4971/events","html_url":"https://github.com/realm/realm-java/issues/4971","id":243103227,"number":4971,"title":"RealmRecyclerViewAdapter's getData() returns old data randomly","user":{"login":"sirudog","id":1550561,"avatar_url":"https://avatars6.githubusercontent.com/u/1550561?v=4","gravatar_id":"","url":"https://api.github.com/users/sirudog","html_url":"https://github.com/sirudog","followers_url":"https://api.github.com/users/sirudog/followers","following_url":"https://api.github.com/users/sirudog/following{/other_user}","gists_url":"https://api.github.com/users/sirudog/gists{/gist_id}","starred_url":"https://api.github.com/users/sirudog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sirudog/subscriptions","organizations_url":"https://api.github.com/users/sirudog/orgs","repos_url":"https://api.github.com/users/sirudog/repos","events_url":"https://api.github.com/users/sirudog/events{/privacy}","received_events_url":"https://api.github.com/users/sirudog/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-07-14T20:26:45Z","updated_at":"2017-07-15T11:55:24Z","closed_at":"2017-07-15T11:34:40Z","body":"<!---\r\n\r\n**Questions**: If you have questions about how to use Realm, ask on\r\n[StackOverflow](http://stackoverflow.com/questions/ask?tags=realm).\r\nWe monitor the `realm` tag.\r\n\r\n**Feature Request**: Just fill in the first two sections below.\r\n\r\n**Bugs**: To help you as fast as possible with an issue please describe your issue\r\nand the steps you have taken to reproduce it in as many details as possible.\r\n\r\n-->\r\nHi, \r\nI have a problem with RealmRecyclerViewAdapter's getData() method. My RealmRecyclerViewAdapter implements Filterable. MyViewHolder extends RecyclerView.ViewHolder and implements View.OnLongClickListener. The filter part works well, I use  RealmRecyclerViewAdapter's updateData() method to update the data associated to the Adapter, but when I long click on a filtered list item and call RealmRecyclerViewAdapter's getData() method, sometimes it returns the old OrderedRealmCollection data,  sometimes it works and I get the updated data back. I have done a lot of debugging, but I was not able to find the reason. It seems quite random. I have also updated io.realm:android-adapters from 2.0.0 to 2.1.0 and io.realm:realm-gradle-plugin from 3.3.2 to 3.5.0, but it did not fix it.\r\nCan you help me to solve my problem?\r\nThanks\r\n\r\n#### Code Sample\r\n\r\n```java\r\n\r\npublic class WordDAdapter extends RealmRecyclerViewAdapter<WordD, WordDAdapter.MyViewHolder> implements Filterable {\r\n    Realm realm = Realm.getDefaultInstance();\r\n    private Activity mActivity;\r\n\r\n    public WordDAdapter(Activity activity, RealmResults<WordD> wordDRealmResults) {\r\n        super(wordDRealmResults, true);\r\n\r\n        this.mActivity = activity;\r\n        registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {\r\n        });\r\n    }\r\n\r\n    @Override\r\n    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {\r\n        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview, parent, false);\r\n        return new MyViewHolder(itemView);\r\n    }\r\n\r\n    @Override\r\n    public void onBindViewHolder(MyViewHolder holder, int position) {\r\n        final WordD wordD = getItem(position);\r\n        holder.language1.setText(wordD.getMlanguage1());\r\n        holder.language2.setText(wordD.getMlanguage2());\r\n        holder.sampleSentence.setText(wordD.getMSampleSentence());\r\n        if (wordD.getIsSelected()){\r\n            holder.MyListView.setBackgroundColor(ContextCompat.getColor(mActivity, R.color.selected));\r\n            holder.language1.setTextColor(ContextCompat.getColor(mActivity, R.color.colorWhite));\r\n            holder.language2.setTextColor(ContextCompat.getColor(mActivity, R.color.colorWhite));\r\n            holder.sampleSentence.setTextColor(ContextCompat.getColor(mActivity, R.color.colorWhite));\r\n        } else {\r\n            if (position % 2 == 0 ) {\r\n                holder.MyListView.setBackgroundColor(ContextCompat.getColor(mActivity, R.color.colorDivider));\r\n            } else  {\r\n                holder.MyListView.setBackgroundColor(ContextCompat.getColor(mActivity, R.color.colorWhite));\r\n            }\r\n            holder.language1.setTextColor(ContextCompat.getColor(mActivity, R.color.secondary_text));\r\n            holder.language2.setTextColor(ContextCompat.getColor(mActivity, R.color.colorPrimaryLight));\r\n            holder.sampleSentence.setTextColor(ContextCompat.getColor(mActivity, R.color.secondary_text));\r\n\r\n        }\r\n    }\r\n\r\n\r\n    public void filterResults(String text) {\r\n        text = text == null ? null : text.toLowerCase().trim();\r\n        if(text == null || \"\".equals(text)) {\r\n            updateData(WordDHelper.getActiveWorkbook().getWords().where().findAll());\r\n        } else {\r\n            updateData(realm.where(WordD.class)\r\n                    .contains(\"mlanguage1\", text, Case.INSENSITIVE)\r\n                    .or()\r\n                    .contains(\"mlanguage2\", text, Case.INSENSITIVE)\r\n                    .findAll());\r\n        }\r\n    }\r\n\r\n    public Filter getFilter() {\r\n        WordDFilter filter = new WordDFilter(this);\r\n        return filter;\r\n    }\r\n\r\n    private class WordDFilter extends Filter {\r\n        private final WordDAdapter adapter;\r\n\r\n        private WordDFilter(WordDAdapter adapter) {\r\n            super();\r\n            this.adapter = adapter;\r\n        }\r\n        @Override\r\n        protected FilterResults performFiltering(CharSequence constraint) {\r\n            return new FilterResults();\r\n        }\r\n\r\n        @Override\r\n        protected void publishResults(CharSequence constraint, Filter.FilterResults results) {\r\n            adapter.filterResults(constraint.toString());\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public int getItemCount() {\r\n        return getData().size();\r\n    }\r\n\r\n    class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {\r\n\r\n            TextView language1;\r\n            TextView language2;\r\n            TextView sampleSentence;\r\n            private LinearLayout MyListView;\r\n\r\n\r\n            MyViewHolder(View view) {\r\n                super(view);\r\n                language1 = (TextView) view.findViewById(R.id.language1);\r\n                language2 = (TextView) view.findViewById(R.id.language2);\r\n                sampleSentence = (TextView) view.findViewById(R.id.sample_sentence);\r\n                MyListView = (LinearLayout) view.findViewById(R.id.list_item);\r\n\r\n                view.setOnLongClickListener(this);\r\n            }\r\n\r\n        @Override\r\n        public boolean onLongClick(View view) {\r\n          int position = getAdapterPosition();\r\n          String selectedWordID = WordDAdapter.this.getData().get(position).getID(); // here getData() returns old data sometimes\r\n           WordD selectedWord =  WordDAdapter.this.getData().get(position);\r\n          WordDHelper.setWorkbookSelected(selectedWord.getWorkbookID());\r\n          WordDHelper.setSelectedWorkbookActive();\r\n            ((MainActivity) mActivity).changeDataset();\r\n            ((MainActivity) mActivity).prepareToolbar(selectedWordID);\r\n            return true;\r\n        }\r\n\r\n        @Override\r\n        public void onClick(View view) {\r\n\r\n            if (MainActivity.isInActionMode) {\r\n                String selectedWordID = getData().get(getAdapterPosition()).getID();\r\n                ((MainActivity) mActivity).prepareSelection(selectedWordID);\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n```\r\n\r\n#### Version of Realm and tooling\r\nRealm version(s): \r\nio.realm:android-adapters: 2.1.0\r\nio.realm:realm-gradle-plugin: 3.5.0\r\n\r\nAndroid Studio version: 2.3.3\r\n\r\nWhich Android version and device: \r\nandroid 7.1.2, API 25\r\ngoogle pixel XL\r\n"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/315529354","html_url":"https://github.com/realm/realm-java/issues/4971#issuecomment-315529354","issue_url":"https://api.github.com/repos/realm/realm-java/issues/4971","id":315529354,"user":{"login":"Zhuinden","id":11718392,"avatar_url":"https://avatars5.githubusercontent.com/u/11718392?v=4","gravatar_id":"","url":"https://api.github.com/users/Zhuinden","html_url":"https://github.com/Zhuinden","followers_url":"https://api.github.com/users/Zhuinden/followers","following_url":"https://api.github.com/users/Zhuinden/following{/other_user}","gists_url":"https://api.github.com/users/Zhuinden/gists{/gist_id}","starred_url":"https://api.github.com/users/Zhuinden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zhuinden/subscriptions","organizations_url":"https://api.github.com/users/Zhuinden/orgs","repos_url":"https://api.github.com/users/Zhuinden/repos","events_url":"https://api.github.com/users/Zhuinden/events{/privacy}","received_events_url":"https://api.github.com/users/Zhuinden/received_events","type":"User","site_admin":false},"created_at":"2017-07-15T11:55:24Z","updated_at":"2017-07-15T11:55:24Z","body":"Nice find. I wouldn't have thought of that. Typically I would just use `updateData()` and it would work."}}
{"actor":{"display_login":"Zhuinden"}}